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.9 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. "fmt"
  4. "time"
  5. "code.gitea.io/gitea/modules/timeutil"
  6. )
  7. const (
  8. StorageScheduleSucceed int = iota
  9. StorageScheduleProcessing
  10. StorageScheduleFailed
  11. StorageNoFile
  12. StorageScheduleWaiting
  13. )
  14. type ScheduleRecord struct {
  15. ID int64 `xorm:"pk autoincr"`
  16. CloudbrainID int64 `xorm:"INDEX NOT NULL unique"`
  17. EndPoint string `xorm:"INDEX NOT NULL"`
  18. Bucket string `xorm:"INDEX NOT NULL"`
  19. ObjectKey string `xorm:"INDEX NOT NULL"`
  20. ProxyServer string `xorm:"INDEX NOT NULL"`
  21. Status int `xorm:"INDEX NOT NULL DEFAULT 0"`
  22. CreatedUnix timeutil.TimeStamp `xorm:"created"`
  23. UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
  24. DeletedAt time.Time `xorm:"deleted"`
  25. }
  26. func updateScheduleCols(e Engine, record *ScheduleRecord, cols ...string) error {
  27. _, err := e.ID(record.ID).Cols(cols...).Update(record)
  28. return err
  29. }
  30. func UpdateScheduleCols(record *ScheduleRecord, cols ...string) error {
  31. return updateScheduleCols(x, record, cols...)
  32. }
  33. func GetSchedulingRecord() ([]*ScheduleRecord, error) {
  34. records := make([]*ScheduleRecord, 0, 10)
  35. return records, x.
  36. Where("status = ?", StorageScheduleProcessing).
  37. Limit(100).
  38. Find(&records)
  39. }
  40. func InsertScheduleRecord(record *ScheduleRecord) (_ *ScheduleRecord, err error) {
  41. if _, err := x.Insert(record); err != nil {
  42. return nil, err
  43. }
  44. return record, nil
  45. }
  46. func getScheduleRecordByPrID(e Engine, cloudbrainId int64) (*ScheduleRecord, error) {
  47. record := new(ScheduleRecord)
  48. has, err := e.Where("cloudbrain_id = ?", cloudbrainId).Get(record)
  49. if err != nil {
  50. return nil, err
  51. } else if !has {
  52. return nil, fmt.Errorf("get record by cloudbrain_id failed(%d)", cloudbrainId)
  53. }
  54. return record, nil
  55. }
  56. func GetScheduleRecordByCloudbrainID(cloudbrainId int64) (*ScheduleRecord, error) {
  57. return getScheduleRecordByPrID(x, cloudbrainId)
  58. }