sys_job.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package apis
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-admin-team/go-admin-core/sdk"
  6. "github.com/go-admin-team/go-admin-core/sdk/api"
  7. "git.cestong.com.cn/cecf/config-center-server/app/jobs/service"
  8. "git.cestong.com.cn/cecf/config-center-server/common/dto"
  9. )
  10. type SysJob struct {
  11. api.Api
  12. }
  13. // RemoveJobForService 调用service实现
  14. func (e SysJob) RemoveJobForService(c *gin.Context) {
  15. v := dto.GeneralDelDto{}
  16. s := service.SysJob{}
  17. err := e.MakeContext(c).
  18. MakeOrm().
  19. Bind(&v).
  20. MakeService(&s.Service).
  21. Errors
  22. if err != nil {
  23. e.Logger.Error(err)
  24. return
  25. }
  26. s.Cron = sdk.Runtime.GetCrontabKey(c.Request.Host)
  27. err = s.RemoveJob(&v)
  28. if err != nil {
  29. e.Logger.Errorf("RemoveJob error, %s", err.Error())
  30. e.Error(500, err, "")
  31. return
  32. }
  33. e.OK(nil, s.Msg)
  34. }
  35. // StartJobForService 启动job service实现
  36. func (e SysJob) StartJobForService(c *gin.Context) {
  37. e.MakeContext(c)
  38. log := e.GetLogger()
  39. db, err := e.GetOrm()
  40. if err != nil {
  41. log.Error(err)
  42. return
  43. }
  44. var v dto.GeneralGetDto
  45. err = c.BindUri(&v)
  46. if err != nil {
  47. log.Warnf("参数验证错误, error: %s", err)
  48. e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
  49. return
  50. }
  51. s := service.SysJob{}
  52. s.Orm = db
  53. s.Log = log
  54. s.Cron = sdk.Runtime.GetCrontabKey(c.Request.Host)
  55. err = s.StartJob(&v)
  56. if err != nil {
  57. log.Errorf("GetCrontabKey error, %s", err.Error())
  58. e.Error(500, err, "")
  59. return
  60. }
  61. e.OK(nil, s.Msg)
  62. }