Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@ func RunJobs(ctx context.Context, jobs []*commonmodels.JobTask, workflowCtx *com
func CleanWorkflowJobs(ctx context.Context, workflowTask *commonmodels.WorkflowTask, workflowCtx *commonmodels.WorkflowTaskCtx, logger *zap.SugaredLogger, ack func()) {
for _, stage := range workflowTask.Stages {
for _, job := range stage.Jobs {
if workflowTask.Status == config.StatusPause && job.JobType == string(config.JobK8sBlueGreenRelease) && job.Status == "" {
continue
}

jobCtl := initJobCtl(job, workflowCtx, logger, ack)
jobCtl.Clean(ctx)
}
}
}

func CleanPendingBlueGreenReleaseJobs(ctx context.Context, workflowTask *commonmodels.WorkflowTask, workflowCtx *commonmodels.WorkflowTaskCtx, logger *zap.SugaredLogger, ack func()) {
for _, stage := range workflowTask.Stages {
for _, job := range stage.Jobs {
if job.JobType != string(config.JobK8sBlueGreenRelease) || job.Status != "" {
continue
}

jobCtl := initJobCtl(job, workflowCtx, logger, ack)
jobCtl.Clean(ctx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func CancelWorkflowTask(userName, workflowName string, taskID int64, logger *zap
return fmt.Errorf("task: %s:%d is passed, cannot cancel", workflowName, taskID)
}

wasPaused := t.Status == config.StatusPause
t.Status = config.StatusCancelled
t.TaskRevoker = userName

Expand All @@ -139,6 +140,26 @@ func CancelWorkflowTask(userName, workflowName string, taskID int64, logger *zap
log.Warnf("Failed to update github check status for custom workflow %s, taskID: %d the error is: %s", t.WorkflowName, t.TaskID, err)
}

if wasPaused {
logger.Infof("clean cancelled paused workflow task resources: %s:%d", t.WorkflowName, t.TaskID)
workflowCtx := &commonmodels.WorkflowTaskCtx{
WorkflowName: t.WorkflowName,
WorkflowDisplayName: t.WorkflowDisplayName,
ProjectName: t.ProjectName,
ProjectDisplayName: t.ProjectDisplayName,
IsDebug: t.IsDebug,
Remark: t.Remark,
TaskID: t.TaskID,
RetryNum: t.RetryNum,
Workspace: "/workspace",
DistDir: fmt.Sprintf("%s/%s/dist/%d", config.S3StoragePath(), t.WorkflowName, t.TaskID),
DockerMountDir: fmt.Sprintf("/tmp/%s/docker/%d", uuid.NewString(), time.Now().Unix()),
ConfigMapMountDir: fmt.Sprintf("/tmp/%s/cm/%d", uuid.NewString(), time.Now().Unix()),
StartTime: time.Now(),
}
jobcontroller.CleanPendingBlueGreenReleaseJobs(context.Background(), t, workflowCtx, logger, func() {})
}

err = cache.NewRedisCache(config2.RedisCommonCacheTokenDB()).Publish(fmt.Sprintf("workflowctl-cancel-%s-%d", workflowName, taskID), "cancel")
if err != nil {
return fmt.Errorf("failed to cancel task: %s:%d, err: %s", workflowName, taskID, err)
Expand Down
Loading