mirror of
1
Fork 0

fix: don't cancel schedule workflows on push to main branch

This commit is contained in:
Kwonunn 2024-10-05 12:14:44 +02:00
parent 1806e336fc
commit b20c0b1469
No known key found for this signature in database
5 changed files with 17 additions and 15 deletions

View File

@ -118,21 +118,23 @@ func DeleteScheduleTaskByRepo(ctx context.Context, id int64) error {
return committer.Commit() return committer.Commit()
} }
func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository) error { func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository, cancelPreviousJobs bool) error {
// If actions disabled when there is schedule task, this will remove the outdated schedule tasks // If actions disabled when there is schedule task, this will remove the outdated schedule tasks
// There is no other place we can do this because the app.ini will be changed manually // There is no other place we can do this because the app.ini will be changed manually
if err := DeleteScheduleTaskByRepo(ctx, repo.ID); err != nil { if err := DeleteScheduleTaskByRepo(ctx, repo.ID); err != nil {
return fmt.Errorf("DeleteCronTaskByRepo: %v", err) return fmt.Errorf("DeleteCronTaskByRepo: %v", err)
} }
// cancel running cron jobs of this repository and delete old schedules if cancelPreviousJobs {
if err := CancelPreviousJobs( // cancel running cron jobs of this repository and delete old schedules
ctx, if err := CancelPreviousJobs(
repo.ID, ctx,
repo.DefaultBranch, repo.ID,
"", repo.DefaultBranch,
webhook_module.HookEventSchedule, "",
); err != nil { webhook_module.HookEventSchedule,
return fmt.Errorf("CancelPreviousJobs: %v", err) ); err != nil {
return fmt.Errorf("CancelPreviousJobs: %v", err)
}
} }
return nil return nil
} }

View File

@ -1056,7 +1056,7 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e
ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err) ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err)
return err return err
} }
if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil { if err := actions_model.CleanRepoScheduleTasks(ctx, repo, true); err != nil {
log.Error("CleanRepoScheduleTasks for archived repo %s/%s: %v", ctx.Repo.Owner.Name, repo.Name, err) log.Error("CleanRepoScheduleTasks for archived repo %s/%s: %v", ctx.Repo.Owner.Name, repo.Name, err)
} }
log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name) log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name)

View File

@ -1031,7 +1031,7 @@ func SettingsPost(ctx *context.Context) {
return return
} }
if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil { if err := actions_model.CleanRepoScheduleTasks(ctx, repo, true); err != nil {
log.Error("CleanRepoScheduleTasks for archived repo %s/%s: %v", ctx.Repo.Owner.Name, repo.Name, err) log.Error("CleanRepoScheduleTasks for archived repo %s/%s: %v", ctx.Repo.Owner.Name, repo.Name, err)
} }

View File

@ -130,7 +130,7 @@ func notify(ctx context.Context, input *notifyInput) error {
return nil return nil
} }
if unit_model.TypeActions.UnitGlobalDisabled() { if unit_model.TypeActions.UnitGlobalDisabled() {
if err := actions_model.CleanRepoScheduleTasks(ctx, input.Repo); err != nil { if err := actions_model.CleanRepoScheduleTasks(ctx, input.Repo, true); err != nil {
log.Error("CleanRepoScheduleTasks: %v", err) log.Error("CleanRepoScheduleTasks: %v", err)
} }
return nil return nil
@ -496,7 +496,7 @@ func handleSchedules(
log.Error("CountSchedules: %v", err) log.Error("CountSchedules: %v", err)
return err return err
} else if count > 0 { } else if count > 0 {
if err := actions_model.CleanRepoScheduleTasks(ctx, input.Repo); err != nil { if err := actions_model.CleanRepoScheduleTasks(ctx, input.Repo, false); err != nil {
log.Error("CleanRepoScheduleTasks: %v", err) log.Error("CleanRepoScheduleTasks: %v", err)
} }
} }

View File

@ -29,7 +29,7 @@ func UpdateRepositoryUnits(ctx context.Context, repo *repo_model.Repository, uni
} }
if slices.Contains(deleteUnitTypes, unit.TypeActions) { if slices.Contains(deleteUnitTypes, unit.TypeActions) {
if err := actions_model.CleanRepoScheduleTasks(ctx, repo); err != nil { if err := actions_model.CleanRepoScheduleTasks(ctx, repo, true); err != nil {
log.Error("CleanRepoScheduleTasks: %v", err) log.Error("CleanRepoScheduleTasks: %v", err)
} }
} }