runservice: move RunEvent to types

This commit is contained in:
Simone Gotti 2019-05-15 09:40:32 +02:00
parent 02e0deec15
commit b95fb98f3c
5 changed files with 12 additions and 12 deletions

View File

@ -22,17 +22,10 @@ import (
"github.com/sorintlab/agola/internal/services/runservice/types"
)
type RunEvent struct {
Sequence string
RunID string
Phase types.RunPhase
Result types.RunResult
}
func NewRunEvent(ctx context.Context, e *etcd.Store, runID string, phase types.RunPhase, result types.RunResult) (*RunEvent, error) {
func NewRunEvent(ctx context.Context, e *etcd.Store, runID string, phase types.RunPhase, result types.RunResult) (*types.RunEvent, error) {
seq, err := sequence.IncSequence(ctx, e, EtcdRunEventSequenceKey)
if err != nil {
return nil, err
}
return &RunEvent{Sequence: seq.String(), RunID: runID, Phase: phase, Result: result}, nil
return &types.RunEvent{Sequence: seq.String(), RunID: runID, Phase: phase, Result: result}, nil
}

View File

@ -465,7 +465,7 @@ func (r *ReadDB) handleRunEvent(tx *db.Tx, ev *etcdclientv3.Event, wresp *etcdcl
func (r *ReadDB) handleRunsEventEvent(tx *db.Tx, ev *etcdclientv3.Event, wresp *etcdclientv3.WatchResponse) error {
switch ev.Type {
case mvccpb.PUT:
var runEvent *common.RunEvent
var runEvent *types.RunEvent
if err := json.Unmarshal(ev.Kv.Value, &runEvent); err != nil {
return errors.Wrap(err, "failed to unmarshal run")
}

View File

@ -475,7 +475,7 @@ func (s *Runservice) scheduleRun(ctx context.Context, r *types.Run, rc *types.Ru
return err
}
var runEvent *common.RunEvent
var runEvent *types.RunEvent
// detect changes to phase and result and set related events
if prevPhase != r.Phase || prevResult != r.Result {
var err error

View File

@ -419,7 +419,7 @@ func GetRun(ctx context.Context, e *etcd.Store, runID string) (*types.Run, int64
return r, resp.Header.Revision, nil
}
func AtomicPutRun(ctx context.Context, e *etcd.Store, r *types.Run, runEvent *common.RunEvent, cgt *types.ChangeGroupsUpdateToken) (*types.Run, error) {
func AtomicPutRun(ctx context.Context, e *etcd.Store, r *types.Run, runEvent *types.RunEvent, cgt *types.ChangeGroupsUpdateToken) (*types.Run, error) {
// check changegroups name
if cgt != nil {
for cgName := range cgt.ChangeGroupsRevisions {

View File

@ -681,3 +681,10 @@ type Executor struct {
// internal values not saved
Revision int64 `json:"-"`
}
type RunEvent struct {
Sequence string
RunID string
Phase RunPhase
Result RunResult
}