You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

schedule_spec.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package actions
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/db"
  7. repo_model "code.gitea.io/gitea/models/repo"
  8. "code.gitea.io/gitea/modules/timeutil"
  9. "github.com/robfig/cron/v3"
  10. )
  11. // ActionScheduleSpec represents a schedule spec of a workflow file
  12. type ActionScheduleSpec struct {
  13. ID int64
  14. RepoID int64 `xorm:"index"`
  15. Repo *repo_model.Repository `xorm:"-"`
  16. ScheduleID int64 `xorm:"index"`
  17. Schedule *ActionSchedule `xorm:"-"`
  18. // Next time the job will run, or the zero time if Cron has not been
  19. // started or this entry's schedule is unsatisfiable
  20. Next timeutil.TimeStamp `xorm:"index"`
  21. // Prev is the last time this job was run, or the zero time if never.
  22. Prev timeutil.TimeStamp
  23. Spec string
  24. Created timeutil.TimeStamp `xorm:"created"`
  25. Updated timeutil.TimeStamp `xorm:"updated"`
  26. }
  27. func (s *ActionScheduleSpec) Parse() (cron.Schedule, error) {
  28. return cronParser.Parse(s.Spec)
  29. }
  30. func init() {
  31. db.RegisterModel(new(ActionScheduleSpec))
  32. }
  33. func UpdateScheduleSpec(ctx context.Context, spec *ActionScheduleSpec, cols ...string) error {
  34. sess := db.GetEngine(ctx).ID(spec.ID)
  35. if len(cols) > 0 {
  36. sess.Cols(cols...)
  37. }
  38. _, err := sess.Update(spec)
  39. return err
  40. }