Skip to content

Commit 83186ec

Browse files
authored
Always delete existing scheduled action tasks (#27662)
Fixes #27650
1 parent 4e98224 commit 83186ec

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

services/actions/notifier_helper.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,6 @@ func handleSchedules(
374374
commit *git.Commit,
375375
input *notifyInput,
376376
) error {
377-
if len(detectedWorkflows) == 0 {
378-
log.Trace("repo %s with commit %s couldn't find schedules", input.Repo.RepoPath(), commit.ID)
379-
return nil
380-
}
381-
382377
branch, err := commit.GetBranchName()
383378
if err != nil {
384379
return err
@@ -388,18 +383,20 @@ func handleSchedules(
388383
return nil
389384
}
390385

391-
rows, _, err := actions_model.FindSchedules(ctx, actions_model.FindScheduleOptions{RepoID: input.Repo.ID})
392-
if err != nil {
393-
log.Error("FindCrons: %v", err)
386+
if count, err := actions_model.CountSchedules(ctx, actions_model.FindScheduleOptions{RepoID: input.Repo.ID}); err != nil {
387+
log.Error("CountSchedules: %v", err)
394388
return err
395-
}
396-
397-
if len(rows) > 0 {
389+
} else if count > 0 {
398390
if err := actions_model.DeleteScheduleTaskByRepo(ctx, input.Repo.ID); err != nil {
399391
log.Error("DeleteCronTaskByRepo: %v", err)
400392
}
401393
}
402394

395+
if len(detectedWorkflows) == 0 {
396+
log.Trace("repo %s with commit %s couldn't find schedules", input.Repo.RepoPath(), commit.ID)
397+
return nil
398+
}
399+
403400
p, err := json.Marshal(input.Payload)
404401
if err != nil {
405402
return fmt.Errorf("json.Marshal: %w", err)

0 commit comments

Comments
 (0)