use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class SaturnExecutor method shutdownUnfinishJob.
private void shutdownUnfinishJob() {
Map<String, JobScheduler> schdMap = JobRegistry.getSchedulerMap().get(executorName);
if (schdMap != null) {
Iterator<String> it = schdMap.keySet().iterator();
while (it.hasNext()) {
String jobName = it.next();
JobScheduler jobScheduler = schdMap.get(jobName);
if (jobScheduler != null) {
if (!regCenter.isConnected() || jobScheduler.getCurrentConf().isEnabled()) {
log.info("[{}] msg=job {} is enabled, force shutdown.", jobName, jobName);
jobScheduler.stopJob(true);
}
jobScheduler.shutdown(false);
}
}
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class ConfigurationServiceTest method test_A_isInPausePeriodDate.
@Test
public void test_A_isInPausePeriodDate() throws Exception {
JobConfiguration jobConfiguration = new JobConfiguration("");
jobConfiguration.setPausePeriodDate("09/11-10/01");
ZookeeperRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration());
zookeeperRegistryCenter.setExecutorName("haha");
ConfigurationService configurationService = new ConfigurationService(new JobScheduler(zookeeperRegistryCenter, jobConfiguration));
try {
Calendar calendar = Calendar.getInstance();
// 注意,日期从0-11,这里实际上是9月
calendar.set(2016, 8, 12, 11, 40);
boolean inPausePeriod = configurationService.isInPausePeriod(calendar.getTime());
assertThat(inPausePeriod).isTrue();
} finally {
JobRegistry.clearExecutor(zookeeperRegistryCenter.getExecutorName());
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class ConfigurationServiceTest method test_A_isInPausePeriodDateAndTime.
@Test
public void test_A_isInPausePeriodDateAndTime() throws Exception {
JobConfiguration jobConfiguration = new JobConfiguration("");
jobConfiguration.setPausePeriodDate("09/11-10/01");
jobConfiguration.setPausePeriodTime("11:30-12:00");
jobConfiguration.setTimeZone(TimeZone.getDefault().getID());
ZookeeperRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration());
zookeeperRegistryCenter.setExecutorName("haha");
ConfigurationService configurationService = new ConfigurationService(new JobScheduler(zookeeperRegistryCenter, jobConfiguration));
try {
Calendar calendar = Calendar.getInstance();
// 注意,日期从0-11,这里实际上是9月
calendar.set(2016, 8, 12, 11, 40);
boolean inPausePeriod = configurationService.isInPausePeriod(calendar.getTime());
assertThat(inPausePeriod).isTrue();
} finally {
JobRegistry.clearExecutor(zookeeperRegistryCenter.getExecutorName());
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class ConfigurationServiceTest method test_A_isInPausePeriodTime.
@Test
public void test_A_isInPausePeriodTime() throws Exception {
JobConfiguration jobConfiguration = new JobConfiguration("");
jobConfiguration.setPausePeriodTime("11:30-12:00");
jobConfiguration.setTimeZone(TimeZone.getDefault().getID());
ZookeeperRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration());
zookeeperRegistryCenter.setExecutorName("haha");
ConfigurationService configurationService = new ConfigurationService(new JobScheduler(zookeeperRegistryCenter, jobConfiguration));
try {
Calendar calendar = Calendar.getInstance();
// 注意,日期从0-11,这里实际上是9月
calendar.set(2016, 8, 12, 11, 40);
boolean inPausePeriod = configurationService.isInPausePeriod(calendar.getTime());
assertThat(inPausePeriod).isTrue();
} finally {
JobRegistry.clearExecutor(zookeeperRegistryCenter.getExecutorName());
}
}
use of com.vip.saturn.job.basic.JobScheduler in project Saturn by vipshop.
the class SaturnExecutor method scheduleJob.
private boolean scheduleJob(String jobName) {
log.info("[{}] msg=add new job {} - {}", jobName, executorName, jobName);
JobConfiguration jobConfig = new JobConfiguration(regCenter, jobName);
if (jobConfig.getSaturnJobClass() == null) {
log.warn("[{}] msg={} - {} the saturnJobClass is null, jobType is {}", jobConfig, executorName, jobName, jobConfig.getJobType());
return false;
}
if (jobConfig.isDeleting()) {
log.warn("[{}] msg={} - {} the job is on deleting", jobName, executorName, jobName);
String serverNodePath = JobNodePath.getServerNodePath(jobName, executorName);
regCenter.remove(serverNodePath);
return false;
}
JobScheduler scheduler = new JobScheduler(regCenter, jobConfig);
scheduler.setSaturnExecutorService(saturnExecutorService);
return scheduler.init();
}
Aggregations