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

schedule_record.go 1.4 kB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package models
  2. import (
  3. "time"
  4. "code.gitea.io/gitea/modules/timeutil"
  5. )
  6. const (
  7. StorageScheduleSucceed int = iota
  8. StorageScheduleProcessing
  9. StorageScheduleFailed
  10. )
  11. type ScheduleRecord struct {
  12. ID int64 `xorm:"pk autoincr"`
  13. CloudbrainID int64 `xorm:"INDEX NOT NULL unique"`
  14. EndPoint string `xorm:"INDEX NOT NULL"`
  15. Bucket string `xorm:"INDEX NOT NULL"`
  16. ObjectKey string `xorm:"INDEX NOT NULL"`
  17. ProxyServer string `xorm:"INDEX NOT NULL"`
  18. Status int `xorm:"INDEX NOT NULL DEFAULT 0"`
  19. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  20. UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
  21. DeletedAt time.Time `xorm:"deleted"`
  22. }
  23. func updateScheduleCols(e Engine, record *ScheduleRecord, cols ...string) error {
  24. _, err := e.ID(record.ID).Cols(cols...).Update(record)
  25. return err
  26. }
  27. func UpdateScheduleCols(record *ScheduleRecord, cols ...string) error {
  28. return updateScheduleCols(x, record, cols...)
  29. }
  30. func GetSchedulingRecord() ([]*ScheduleRecord, error) {
  31. records := make([]*ScheduleRecord, 0, 10)
  32. return records, x.
  33. Where("status = ?", StorageScheduleProcessing).
  34. Limit(100).
  35. Find(&records)
  36. }
  37. func InsertScheduleRecord(record *ScheduleRecord) (_ *ScheduleRecord, err error) {
  38. if _, err := x.Insert(record); err != nil {
  39. return nil, err
  40. }
  41. return record, nil
  42. }