Skip to content

Commit

Permalink
Merge pull request #197 from go-atomci/feat-sync-publishjob
Browse files Browse the repository at this point in the history
🦄 refactor: when  job 404, add default value
  • Loading branch information
colynn authored Jun 26, 2023
2 parents 229d8ab + cb1ac0d commit 6582936
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/core/publish/uitls.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (pm *PublishManager) getPublishItemCanEnableOperations(item *models.Publish
operations.BackTo = false
case models.Running, models.Pending:
operations = getOperationCanEnableByStepStatus(item.StepType, item.Status, operations)
case models.Failed:
case models.Failed, models.UnKnown:
operations = getOperationCanEnableByStepStatus(item.StepType, item.Status, operations)
case models.Success:
nextStep, err := pm.pipelineHandler.GetNextStepTypeByStageID(item.LastPipelineInstanceID, item.StageID, item.StepIndex)
Expand Down
17 changes: 14 additions & 3 deletions internal/cronjob/publishjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package cronjob

import (
"fmt"
"strings"
"time"

"github.com/go-atomci/atomci/internal/core/pipelinemgr"
"github.com/go-atomci/atomci/internal/dao"
"github.com/go-atomci/atomci/internal/middleware/log"
"github.com/go-atomci/atomci/internal/models"
"github.com/go-atomci/atomci/utils"
"github.com/go-atomci/workflow"

"github.com/go-atomci/workflow/jenkins"
)
Expand Down Expand Up @@ -61,7 +63,7 @@ func syncAllPublishJobStatus() {
}

func getRunningPublishJob(newPublishJob *dao.PublishJobModel) []*models.PublishJob {
publishJobs, err := newPublishJob.GetPublishJobsByFilter([]string{models.StatusRunning, models.StatusUnknown, models.StatusInit}, []string{models.JobTypeBuild, models.JobTypeDeploy})
publishJobs, err := newPublishJob.GetPublishJobsByFilter([]string{models.StatusRunning, models.StatusInit}, []string{models.JobTypeBuild, models.JobTypeDeploy})
if err != nil {
log.Log.Error("when sync publish job, get publish jobs occur error: %s", err.Error())
return nil
Expand Down Expand Up @@ -128,7 +130,16 @@ func getPipelineJobStatus(jobName string, job *models.PublishJob, pipeline *pipe

jobDetail, err := workFlowProvider.GetJobInfo(job.RunID)
if err != nil {
return nil, 0, err
if strings.Contains(err.Error(), "404 not found") {
// when job 404/ set jobDetail default value.
jobDetail = &workflow.JobInfo{
Result: models.StatusUnknown,
DurationMillis: 0,
Stages: []workflow.Stage{},
}
} else {
return nil, 0, err
}
}

// get job result and execute time
Expand Down Expand Up @@ -171,7 +182,7 @@ func getPipelineJobStatus(jobName string, job *models.PublishJob, pipeline *pipe
case "IN_PROGRESS":
jobStatus = models.StatusRunning
default:
log.Log.Error("job's status is undesired value: %v, reset job status to: 'UNKNOWN'", status)
log.Log.Warn("job's status is undesired value: %v, reset job status to: 'UNKNOWN'", status)
jobStatus = models.StatusUnknown
publishStatus = models.UnKnown
}
Expand Down

0 comments on commit 6582936

Please sign in to comment.