use of com.thoughtworks.go.config.TimerConfig in project gocd by gocd.
the class TimedBuild method canProduce.
public void canProduce(PipelineConfig pipelineConfig, SchedulingCheckerService schedulingChecker, ServerHealthService serverHealthService, OperationResult operationResult) {
schedulingChecker.canTriggerPipelineWithTimer(pipelineConfig, operationResult);
if (!operationResult.canContinue()) {
ServerHealthState serverHealthState = operationResult.getServerHealthState();
LOGGER.info(String.format("'%s' because '%s'", serverHealthState.getMessage(), serverHealthState.getDescription()));
} else {
TimerConfig timer = pipelineConfig.getTimer();
String timerSpec = timer == null ? "Missing timer spec" : timer.getTimerSpec();
LOGGER.info(String.format("Timer scheduling pipeline '%s' using spec '%s'", pipelineConfig.name(), timerSpec));
}
}
use of com.thoughtworks.go.config.TimerConfig in project gocd by gocd.
the class TimerScheduler method scheduleJob.
private void scheduleJob(Scheduler scheduler, PipelineConfig pipelineConfig) {
TimerConfig timer = pipelineConfig.getTimer();
if (timer != null) {
try {
Trigger trigger = new CronTrigger(CaseInsensitiveString.str(pipelineConfig.name()), QUARTZ_GROUP, timer.getTimerSpec());
JobDetail jobDetail = new JobDetail(CaseInsensitiveString.str(pipelineConfig.name()), QUARTZ_GROUP, SchedulePipelineQuartzJob.class);
jobDetail.setJobDataMap(jobDataMapFor(pipelineConfig));
scheduler.scheduleJob(jobDetail, trigger);
LOG.info("Initialized timer for pipeline " + pipelineConfig.name() + " with " + timer.getTimerSpec());
} catch (ParseException e) {
showPipelineError(pipelineConfig, e, "Bad timer specification for timer in Pipeline: " + pipelineConfig.name(), "Cannot schedule pipeline using the timer");
} catch (SchedulerException e) {
showPipelineError(pipelineConfig, e, "Could not register pipeline '" + pipelineConfig.name() + "' with timer", "");
}
}
}
use of com.thoughtworks.go.config.TimerConfig in project gocd by gocd.
the class TimerSchedulerTest method shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges.
@Test
public void shouldRescheduleTimerTriggerPipelineWhenItsConfigChanges() throws SchedulerException {
GoConfigService goConfigService = mock(GoConfigService.class);
when(schedulerFactory.getScheduler()).thenReturn(scheduler);
String pipelineName = "timer-based-pipeline";
when(scheduler.getJobDetail(pipelineName, TimerScheduler.QUARTZ_GROUP)).thenReturn(mock(JobDetail.class));
TimerScheduler timerScheduler = new TimerScheduler(schedulerFactory, goConfigService, null, null);
ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
doNothing().when(goConfigService).register(captor.capture());
timerScheduler.initialize();
List<ConfigChangedListener> listeners = captor.getAllValues();
assertThat(listeners.get(1) instanceof EntityConfigChangedListener, is(true));
EntityConfigChangedListener<PipelineConfig> pipelineConfigChangeListener = (EntityConfigChangedListener<PipelineConfig>) listeners.get(1);
PipelineConfig pipelineConfig = mock(PipelineConfig.class);
when(pipelineConfig.name()).thenReturn(new CaseInsensitiveString(pipelineName));
when(pipelineConfig.getTimer()).thenReturn(new TimerConfig("* * * * * ?", true));
ArgumentCaptor<JobDetail> jobDetailArgumentCaptor = ArgumentCaptor.forClass(JobDetail.class);
ArgumentCaptor<CronTrigger> triggerArgumentCaptor = ArgumentCaptor.forClass(CronTrigger.class);
when(scheduler.scheduleJob(jobDetailArgumentCaptor.capture(), triggerArgumentCaptor.capture())).thenReturn(new Date());
pipelineConfigChangeListener.onEntityConfigChange(pipelineConfig);
assertThat(jobDetailArgumentCaptor.getValue().getName(), is(pipelineName));
assertThat(triggerArgumentCaptor.getValue().getCronExpression(), is("* * * * * ?"));
verify(schedulerFactory).getScheduler();
verify(scheduler).start();
verify(scheduler).getJobDetail(pipelineName, TimerScheduler.QUARTZ_GROUP);
verify(scheduler).unscheduleJob(pipelineName, TimerScheduler.QUARTZ_GROUP);
verify(scheduler).deleteJob(pipelineName, TimerScheduler.QUARTZ_GROUP);
verify(scheduler).scheduleJob(jobDetailArgumentCaptor.getValue(), triggerArgumentCaptor.getValue());
}
Aggregations