|
|
|
package com.glxp.api.task;
|
|
|
|
|
|
|
|
import com.glxp.api.dao.schedule.ScheduledDao;
|
|
|
|
import com.glxp.api.dao.system.SyncDataSetDao;
|
|
|
|
import com.glxp.api.entity.system.ScheduledEntity;
|
|
|
|
import com.glxp.api.entity.system.SyncDataSetEntity;
|
|
|
|
import com.glxp.api.req.system.ScheduledRequest;
|
|
|
|
import com.glxp.api.service.sync.HeartService;
|
|
|
|
import com.glxp.api.util.RedisUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
|
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
|
|
import org.springframework.scheduling.support.CronTrigger;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@Component
|
|
|
|
@EnableScheduling
|
|
|
|
public class SyncHeartTask implements SchedulingConfigurer {
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
protected ScheduledDao scheduledDao;
|
|
|
|
@Resource
|
|
|
|
SyncHeartService syncHeartService;
|
|
|
|
@Resource
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
@Resource
|
|
|
|
HeartService heartService;
|
|
|
|
@Resource
|
|
|
|
private SyncDataSetDao syncDataSetDao;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
|
|
|
|
|
|
|
scheduledTaskRegistrar.addTriggerTask(() -> process(),
|
|
|
|
triggerContext -> {
|
|
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
|
|
scheduledRequest.setCronName("heartTask");
|
|
|
|
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
|
|
|
|
String cron = scheduledEntity.getCron();
|
|
|
|
if (cron.isEmpty()) {
|
|
|
|
log.error("cron is null");
|
|
|
|
}
|
|
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void process() {
|
|
|
|
syncHeartService.syncProcess();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|