Skip to content

Commit

Permalink
fix (api): compare change status notif (#1590)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored and fsamin committed Nov 28, 2017
1 parent f01113d commit be28c8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion engine/api/notification/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ShouldSendUserNotification(notif sdk.UserNotificationSettings, current *sdk
if previous == nil {
return true
}
return current.Status != previous.Status
return current.Status.String() != previous.Status.String()
}
return false
}
Expand Down
2 changes: 2 additions & 0 deletions engine/api/workflow/workflow_run_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ func GetWorkflowRunEventData(cError <-chan error, cEvent <-chan interface{}) ([]
for {
select {
case e, has := <-cError:
log.Info("GetWorkflowRunEventData> cError has: %t err:%s", has, e)
if !has {
return wrs, wnrs, wnjrs, nil
}
if e != nil {
return nil, nil, nil, e
}
case w, has := <-cEvent:
log.Info("GetWorkflowRunEventData> cEvent has: %t", has)
if !has {
return wrs, wnrs, wnjrs, nil
}
Expand Down
11 changes: 11 additions & 0 deletions engine/api/workflow_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,20 @@ func (api *API) postWorkflowJobResultHandler() Handler {
return sdk.WrapError(err, "postWorkflowJobResultHandler> cannot unmarshal request")
}

log.Info("postWorkflowJobResultHandler> start res.BuildID %d", res.BuildID)

chanEvent := make(chan interface{}, 1)
chanError := make(chan error, 1)
go postJobResult(chanEvent, chanError, api.mustDB(), api.Cache, p, getWorker(ctx), &res)

workflowRuns, workflowNodeRuns, workflowNodeJobRuns, err := workflow.GetWorkflowRunEventData(chanError, chanEvent)
if err != nil {
log.Info("postWorkflowJobResultHandler> end with err res.BuildID %d, err:%s", res.BuildID, err)
return err
}
go workflow.SendEvent(api.mustDB(), workflowRuns, workflowNodeRuns, workflowNodeJobRuns, p.Key)

log.Info("postWorkflowJobResultHandler> end res.BuildID %d", res.BuildID)
return nil
}
}
Expand All @@ -257,6 +261,7 @@ func postJobResult(chEvent chan<- interface{}, chError chan<- error, db *gorp.Db
//Start the transaction
tx, errb := db.Begin()
if errb != nil {
log.Info("postJobResult> Cannot begin tx job %d", res.BuildID)
chError <- sdk.WrapError(errb, "postJobResult> Cannot begin tx")
return
}
Expand All @@ -265,12 +270,14 @@ func postJobResult(chEvent chan<- interface{}, chError chan<- error, db *gorp.Db
//Load workflow node job run
job, errj := workflow.LoadAndLockNodeJobRunWait(tx, store, res.BuildID)
if errj != nil {
log.Info("postWorkflowJobResultHandler> Unable to load node run job %d", res.BuildID)
chError <- sdk.WrapError(errj, "postJobResult> Unable to load node run job %d", res.BuildID)
return
}

remoteTime, errt := ptypes.Timestamp(res.RemoteTime)
if errt != nil {
log.Info("postJobResult> Cannot parse remote time job %d", res.BuildID)
chError <- sdk.WrapError(errt, "postJobResult> Cannot parse remote time")
return
}
Expand All @@ -281,24 +288,28 @@ func postJobResult(chEvent chan<- interface{}, chError chan<- error, db *gorp.Db
}}

if err := workflow.AddSpawnInfosNodeJobRun(tx, store, p, job.ID, workflow.PrepareSpawnInfos(infos)); err != nil {
log.Info("postJobResult> Cannot save spawn info job %d", job.ID)
chError <- sdk.WrapError(err, "postJobResult> Cannot save spawn info job %d", job.ID)
}

// Update action status
log.Debug("postJobResult> Updating %d to %s in queue", job.ID, res.Status)
if err := workflow.UpdateNodeJobRunStatus(tx, store, p, job, sdk.Status(res.Status), chEvent); err != nil {
log.Info("postJobResult> Cannot update NodeJobRun %d status", job.ID)
chError <- sdk.WrapError(err, "postJobResult> Cannot update NodeJobRun %d status", job.ID)
return
}

//Update worker status
if err := worker.UpdateWorkerStatus(tx, wr.ID, sdk.StatusWaiting); err != nil {
log.Info("postJobResult> Cannot update worker %d status", wr.ID)
chError <- sdk.WrapError(err, "postJobResult> Cannot update worker %d status", wr.ID)
return
}

//Commit the transaction
if err := tx.Commit(); err != nil {
log.Info("postJobResult> Cannot commit tx")
chError <- sdk.WrapError(err, "postJobResult> Cannot commit tx")
return
}
Expand Down

0 comments on commit be28c8b

Please sign in to comment.