Skip to content

Commit

Permalink
refactor(actions): CreateScheduleTask
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy committed Mar 10, 2023
1 parent f1eb0ad commit fffb455
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions models/actions/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ func init() {
}

// CreateScheduleTask creates new schedule task.
func CreateScheduleTask(ctx context.Context, id int64, rows []*ActionSchedule) error {
for _, row := range rows {
if _, err := db.GetEngine(ctx).Insert(row); err != nil {
func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil {
return err
}
defer committer.Close()

if len(rows) > 0 {
if err = db.Insert(ctx, rows); err != nil {
return err
}
}

return nil
return committer.Commit()
}

func DeleteScheduleTaskByRepo(ctx context.Context, id int64) error {
Expand Down
4 changes: 2 additions & 2 deletions services/actions/notifier_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ func handleSchedules(
cron.EntryIDs = entryIDs
}

if err := actions_model.CreateScheduleTask(ctx, input.Repo.ID, crons); err != nil {
log.Error("CreateCronTask: %v", err)
if err := actions_model.CreateScheduleTask(ctx, crons); err != nil {
log.Error("CreateScheduleTask: %v", err)
}
}

Expand Down

0 comments on commit fffb455

Please sign in to comment.