QuartzFactory.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2018-2025, hnqz All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the pig4cloud.com developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: hnqz
  16. */
  17. package net.yyc.quartz.config;
  18. import cn.hutool.core.util.IdUtil;
  19. import net.yyc.quartz.constants.JobTypeQuartzEnum;
  20. import net.yyc.quartz.constants.QuartzEnum;
  21. import net.yyc.quartz.entity.SysJob;
  22. import lombok.SneakyThrows;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.quartz.DisallowConcurrentExecution;
  25. import org.quartz.Job;
  26. import org.quartz.JobExecutionContext;
  27. import javax.annotation.Resource;
  28. /**
  29. * @author 郑健楠
  30. *
  31. * <p>
  32. * 动态任务工厂
  33. */
  34. @Slf4j
  35. @DisallowConcurrentExecution
  36. public class QuartzFactory implements Job {
  37. @Resource
  38. private QuartzInvokeFactory quartzInvokeFactory;
  39. @Override
  40. @SneakyThrows
  41. public void execute(JobExecutionContext jobExecutionContext) {
  42. SysJob sysJob = (SysJob) jobExecutionContext.getMergedJobDataMap()
  43. .get(QuartzEnum.SCHEDULE_JOB_KEY.getType());
  44. String executionId = IdUtil.fastSimpleUUID();
  45. String jobType = sysJob.getJobType();
  46. if (JobTypeQuartzEnum.REST.getType().equals(jobType) || JobTypeQuartzEnum.JAR.getType().equals(jobType)) {
  47. log.info("[QUARTZ] [{}] 任务开始 | jobId={} jobName={} jobGroup={} type={} url={}",
  48. executionId, sysJob.getJobId(), sysJob.getJobName(), sysJob.getJobGroup(),
  49. jobType, sysJob.getExecutePath());
  50. } else {
  51. log.info("[QUARTZ] [{}] 任务开始 | jobId={} jobName={} jobGroup={} type={} class={} method={}",
  52. executionId, sysJob.getJobId(), sysJob.getJobName(), sysJob.getJobGroup(),
  53. jobType, sysJob.getClassName(), sysJob.getMethodName());
  54. }
  55. quartzInvokeFactory.init(sysJob, jobExecutionContext.getTrigger(), executionId);
  56. }
  57. }