mindlesscloud commented on code in PR #4158:
URL: 
https://github.com/apache/incubator-devlake/pull/4158#discussion_r1064551593


##########
services/pipeline_runner.go:
##########
@@ -126,18 +127,81 @@ func runPipeline(pipelineId uint64) errors.Error {
                dbPipeline.SpentSeconds = int(finishedAt.Unix() - 
dbPipeline.BeganAt.Unix())
        }
        if err != nil {
-               dbPipeline.Status = models.TASK_FAILED
                dbPipeline.Message = err.Error()
                dbPipeline.ErrorName = err.Messages().Format()
-       } else {
-               dbPipeline.Status = models.TASK_COMPLETED
-               dbPipeline.Message = ""
+       }
+       dbPipeline.Status, err = computePipelineStatus(dbPipeline)
+       if err != nil {
+               globalPipelineLog.Error(err, "compute pipeline status failed")
+               return err
        }
        err = db.Update(dbPipeline)
        if err != nil {
                globalPipelineLog.Error(err, "update pipeline state failed")
-               return errors.Convert(err)
+               return err
        }
        // notify external webhook
        return NotifyExternal(pipelineId)
 }
+
+// computePipelineStatus determines pipleline status by its latest(rerun 
included) tasks statuses
+// 1. TASK_COMPLETED: all tasks were executed sucessfully
+// 2. TASK_FAILED: SkipOnFail=false with failed task(s)
+// 3. TASK_PARTIAL: SkipOnFail=true with failed task(s)
+func computePipelineStatus(pipeline *models.DbPipeline) (string, errors.Error) 
{
+       tasks, err := GetLatestTasksOfPipeline(pipeline)
+       if err != nil {
+               return "", err
+       }
+       succeeded, failed := 0, 0
+
+       for _, task := range tasks {
+               if task.Status == models.TASK_COMPLETED {
+                       succeeded += 1
+               } else if task.Status == models.TASK_FAILED || task.Status == 
models.TASK_CANCELLED {
+                       failed += 1
+               } else {
+                       return "", errors.Default.New("unexpected status, did 
you call computePipelineStatus at a wrong timing?")

Review Comment:
   some tasks may have a status of `TASK_CREATED` and `TASK_RERUN`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to