task_dispatch_done.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package archive
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _inDispatchDoneSQL = `INSERT IGNORE INTO task_dispatch_done(task_id,pool,subject,adminid,aid,cid,uid,state,utime,ctime,mtime,dtime,gtime,weight,conf_id,conf_state,conf_weight,upspecial,ptime,uptime,cftime)
  10. SELECT id,pool,subject,adminid,aid,cid,uid,state,utime,ctime,mtime,dtime,gtime,weight,conf_id,conf_state,conf_weight,upspecial,ptime,uptime,cftime FROM task_dispatch WHERE mtime>=? AND mtime<=? AND state IN (2,6);`
  11. _delTaskDoneBeforeSQL = "DELETE FROM task_dispatch_done WHERE mtime<=? LIMIT ?"
  12. _delTaskBeforeSQL = "DELETE FROM task_dispatch WHERE mtime<=? LIMIT ?"
  13. )
  14. // TxAddDispatchDone add task dispatch done
  15. func (d *Dao) TxAddDispatchDone(c context.Context, tx *sql.Tx, startTime, endTime time.Time) (rows int64, err error) {
  16. res, err := tx.Exec(_inDispatchDoneSQL, startTime.Format("2006-01-02 15:04:05"), endTime.Format("2006-01-02 15:04:05"))
  17. if err != nil {
  18. log.Error("tx.Exec(%s, %s, %s) error(%v)", _inDispatchDoneSQL, startTime.Format("2006-01-02 15:04:05"), endTime.Format("2006-01-02 15:04:05"), err)
  19. return
  20. }
  21. return res.RowsAffected()
  22. }
  23. // DelTaskDoneBefore del task_dispatch_done
  24. func (d *Dao) DelTaskDoneBefore(c context.Context, before time.Time, limit int64) (rows int64, err error) {
  25. res, err := d.db.Exec(c, _delTaskDoneBeforeSQL, before.Format("2006-01-02 15:04:05"), limit)
  26. if err != nil {
  27. log.Error("d.db.Exec(%s, %s, %d) error(%v)", _delTaskDoneBeforeSQL, before, limit, err)
  28. return
  29. }
  30. return res.RowsAffected()
  31. }
  32. // DelTaskBefore del task_dispatch
  33. func (d *Dao) DelTaskBefore(c context.Context, before time.Time, limit int64) (rows int64, err error) {
  34. res, err := d.db.Exec(c, _delTaskBeforeSQL, before.Format("2006-01-02 15:04:05"), limit)
  35. if err != nil {
  36. log.Error("d.db.Exec(%s, %s, %d) error(%v)", _delTaskBeforeSQL, before, limit, err)
  37. return
  38. }
  39. return res.RowsAffected()
  40. }