ScheduleConfig.java 926 B

12345678910111213141516171819202122232425262728293031323334
  1. package cn.com.qmth.examcloud.tool.config;
  2. import cn.com.qmth.examcloud.tool.service.TaskService;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.scheduling.annotation.EnableScheduling;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import org.springframework.stereotype.Component;
  9. @Component
  10. @EnableScheduling
  11. public class ScheduleConfig {
  12. private static final Logger log = LoggerFactory.getLogger(ScheduleConfig.class);
  13. @Autowired
  14. private TaskService taskService;
  15. /**
  16. * 定时执行任务(每N秒执行)
  17. */
  18. @Scheduled(cron = "0/10 * * * * ?")
  19. public void execute() {
  20. Long taskId = taskService.getFirstWaitingTaskId();
  21. if (taskId == null) {
  22. log.info("no task...");
  23. return;
  24. }
  25. taskService.executeTask(taskId);
  26. }
  27. }