task_queue.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package settings
  2. type TaskQueue struct {
  3. MaxRetryTimes int `json:"max_retry_times" default:"3"` // 单个任务失败后,最大重试次数,超过后会降一级
  4. OneJobTimeOut int `json:"one_job_time_out" default:"300"` // 单个任务的超时时间 5 * 60 s
  5. Interval int `json:"interval" default:"10"` // 任务的间隔,单位 s,这里会有一个限制,不允许太快,然后会做一定的随机时间范围,当前值 x ~ 2*x 之内随机
  6. ExpirationTime int `json:"expiration_time" default:"90"` // 单位天。1. 一个视频的 CreatedTime 在这个时间范围内,都会被下载字幕(除非已经观看跳过启用了)。2. 如果下载失败的任务,AddTime 超过了这个时间,那么就标记为 Failed
  7. DownloadSubDuringXDays int `json:"download_sub_during_x_days" default:"7"` // 如果创建了 x 天,且有内置的中文字幕,那么也不进行下载了
  8. OneSubDownloadInterval int `json:"one_sub_download_interval" default:"12"` // 一个字幕下载的间隔(单位 h),不然老是一个循环。对比的基准是 OneJob 的 UpdateTime
  9. CheckPublicIPTargetSite string `json:"check_pulic_ip_target_site" default:""` // 检测本机外网 IP 的目标地址,必须是返回直接的 IP 字符串,不需要解析。; 分割
  10. }
  11. func NewTaskQueue() *TaskQueue {
  12. return &TaskQueue{
  13. MaxRetryTimes: 3,
  14. OneJobTimeOut: 300,
  15. Interval: 10,
  16. ExpirationTime: 90,
  17. DownloadSubDuringXDays: 7,
  18. OneSubDownloadInterval: 12,
  19. CheckPublicIPTargetSite: "",
  20. }
  21. }
  22. func (t *TaskQueue) Check() {
  23. if t.MaxRetryTimes < 1 || t.MaxRetryTimes > 5 {
  24. t.MaxRetryTimes = 3
  25. }
  26. if t.OneJobTimeOut < 300 || t.OneJobTimeOut > 600 {
  27. t.OneJobTimeOut = 300
  28. }
  29. if t.Interval < 10 || t.Interval > 60 {
  30. t.Interval = 10
  31. }
  32. if t.ExpirationTime < 1 || t.ExpirationTime > 180 {
  33. t.ExpirationTime = 90
  34. }
  35. if t.DownloadSubDuringXDays < 1 || t.DownloadSubDuringXDays > 30 {
  36. t.DownloadSubDuringXDays = 7
  37. }
  38. if t.OneSubDownloadInterval < 12 || t.OneSubDownloadInterval > 48 {
  39. t.OneSubDownloadInterval = 12
  40. }
  41. }