12345678910111213141516171819202122232425262728293031323334 |
- package cn.com.qmth.examcloud.tool.config;
- import cn.com.qmth.examcloud.tool.service.TaskService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- @Component
- @EnableScheduling
- public class ScheduleConfig {
- private static final Logger log = LoggerFactory.getLogger(ScheduleConfig.class);
- @Autowired
- private TaskService taskService;
- /**
- * 定时执行任务(每N秒执行)
- */
- @Scheduled(cron = "0/10 * * * * ?")
- public void execute() {
- Long taskId = taskService.getFirstWaitingTaskId();
- if (taskId == null) {
- log.info("no task...");
- return;
- }
- taskService.executeTask(taskId);
- }
- }
|