You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-wms-java/src/main/java/com/glxp/api/task/SyncHeartTask.java

58 lines
1.9 KiB
Java

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;
2 years ago
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");
9 months ago
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();
}
}