CronJobMessageHandler.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2019 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * >>
  17. *
  18. */
  19. package edp.davinci.service.impl;
  20. import com.alibaba.fastjson.JSON;
  21. import edp.core.utils.QuartzHandler;
  22. import edp.davinci.core.enums.CronJobStatusEnum;
  23. import edp.davinci.core.enums.LogNameEnum;
  24. import edp.davinci.core.service.RedisMessageHandler;
  25. import edp.davinci.dao.CronJobMapper;
  26. import edp.davinci.model.CronJob;
  27. import lombok.extern.slf4j.Slf4j;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.stereotype.Component;
  32. import java.io.Serializable;
  33. import java.util.Date;
  34. @Slf4j
  35. @Component
  36. public class CronJobMessageHandler implements Serializable,RedisMessageHandler {
  37. private static final Logger scheduleLogger = LoggerFactory.getLogger(LogNameEnum.BUSINESS_SCHEDULE.getName());
  38. private static final long serialVersionUID = -6164416250269765727L;
  39. @Autowired
  40. private CronJobMapper cronJobMapper;
  41. @Autowired
  42. private QuartzHandler quartzHandler;
  43. @Override
  44. public void handle(Object message, String flag) {
  45. // the flag is deprecated
  46. log.info("CronJobHandler received stop message({}), flag:{}", message, flag);
  47. if (!(message instanceof String)) {
  48. return;
  49. }
  50. CronJob cronJob = JSON.parseObject((String) message, CronJob.class);
  51. quartzHandler.removeJob(cronJob);
  52. scheduleLogger.info("CronJob({}) is stopped", cronJob.getId());
  53. cronJob.setJobStatus(CronJobStatusEnum.STOP.getStatus());
  54. cronJob.setUpdateTime(new Date());
  55. cronJobMapper.update(cronJob);
  56. }
  57. }