models.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package worker
  2. import (
  3. "sync"
  4. "time"
  5. "gorm.io/gorm"
  6. )
  7. type QorJob struct {
  8. gorm.Model
  9. Job string
  10. Status string `sql:"default:'new'"`
  11. Args interface{} `sql:"-" gorm:"-"`
  12. }
  13. type QorJobInstance struct {
  14. gorm.Model
  15. QorJobID uint `gorm:"index"`
  16. Operator string
  17. Job string
  18. Status string `sql:"default:'new'"`
  19. Args string
  20. Context string
  21. Progress uint
  22. ProgressText string
  23. jb *JobBuilder `sql:"-"`
  24. mutex sync.Mutex `sql:"-"`
  25. stopRefresh bool `sql:"-"`
  26. inRefresh bool `sql:"-"`
  27. }
  28. type QorJobLog struct {
  29. ID uint `gorm:"primarykey"`
  30. CreatedAt time.Time `gorm:"index"`
  31. QorJobInstanceID uint `gorm:"index"`
  32. Log string
  33. }
  34. type Scheduler interface {
  35. GetScheduleTime() *time.Time
  36. SetScheduleTime(t *time.Time)
  37. }
  38. // Schedule could be embedded as job argument, then the job will get run as scheduled feature
  39. type Schedule struct {
  40. ScheduleTime *time.Time
  41. }
  42. // GetScheduleTime get scheduled time
  43. func (schedule *Schedule) GetScheduleTime() *time.Time {
  44. if scheduleTime := schedule.ScheduleTime; scheduleTime != nil {
  45. if scheduleTime.After(time.Now().Add(time.Minute)) {
  46. return scheduleTime
  47. }
  48. }
  49. return nil
  50. }
  51. func (schedule *Schedule) SetScheduleTime(t *time.Time) {
  52. schedule.ScheduleTime = t
  53. }
  54. type GoQueError struct {
  55. gorm.Model
  56. Error string
  57. }