use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.
the class ScheduledDistributionTrigger method register.
public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
try {
ScheduleOptions options = scheduler.NOW(-1, secondsInterval);
String jobName = getJobName(requestHandler);
options.name(jobName);
options.canRunConcurrently(false);
options.onLeaderOnly(true);
boolean success = scheduler.schedule(new ScheduledDistribution(requestHandler), options);
if (success) {
registeredJobs.add(jobName);
}
log.info("handler registered {} {}", jobName, success);
} catch (Exception e) {
throw new DistributionException("unable to register handler " + requestHandler, e);
}
}
use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.
the class ScheduledDistributionTriggerTest method testRegister.
@Test
public void testRegister() throws Exception {
String path = "/path/to/somewhere";
int interval = 10;
DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
Scheduler scheduler = mock(Scheduler.class);
ScheduleOptions options = mock(ScheduleOptions.class);
when(scheduler.NOW(-1, interval)).thenReturn(options);
when(options.name(handler.toString())).thenReturn(options);
ScheduledDistributionTrigger scheduleddistributionTrigger = new ScheduledDistributionTrigger(action.name(), path, interval, null, scheduler, mock(ResourceResolverFactory.class));
scheduleddistributionTrigger.register(handler);
}
use of org.apache.sling.commons.scheduler.ScheduleOptions in project sling by apache.
the class JobSchedulerImpl method startScheduledJob.
/**
* Start a scheduled job
* @param info The scheduling info
*/
private void startScheduledJob(final ScheduledJobInfoImpl info) {
if (this.active.get()) {
if (!info.isSuspended()) {
this.configuration.getAuditLogger().debug("SCHEDULED OK name={}, topic={}, properties={} : {}", new Object[] { info.getName(), info.getJobTopic(), info.getJobProperties() }, info.getSchedules());
int index = 0;
for (final ScheduleInfo si : info.getSchedules()) {
final String name = info.getSchedulerJobId() + "-" + String.valueOf(index);
ScheduleOptions options = null;
switch(si.getType()) {
case DAILY:
case WEEKLY:
case HOURLY:
case MONTHLY:
case YEARLY:
case CRON:
options = this.scheduler.EXPR(((ScheduleInfoImpl) si).getCronExpression());
break;
case DATE:
options = this.scheduler.AT(((ScheduleInfoImpl) si).getNextScheduledExecution());
break;
}
// Create configuration for scheduled job
final Map<String, Serializable> config = new HashMap<>();
config.put(PROPERTY_READ_JOB, info);
config.put(PROPERTY_SCHEDULE_INDEX, index);
this.scheduler.schedule(this, options.name(name).config(config).canRunConcurrently(false));
index++;
}
} else {
this.configuration.getAuditLogger().debug("SCHEDULED SUSPENDED name={}, topic={}, properties={} : {}", new Object[] { info.getName(), info.getJobTopic(), info.getJobProperties(), info.getSchedules() });
}
}
}
use of org.apache.sling.commons.scheduler.ScheduleOptions in project acs-aem-commons by Adobe-Consulting-Services.
the class SyntheticWorkflowRunnerImpl method getOptions.
@Override
public ScheduleOptions getOptions(Config config) {
ScheduleOptions options = scheduler.NOW();
options.canRunConcurrently(false);
options.onLeaderOnly(true);
options.name(config.getWorkspace().getJobName());
return options;
}
use of org.apache.sling.commons.scheduler.ScheduleOptions in project acs-aem-commons by Adobe-Consulting-Services.
the class BulkWorkflowEngineImpl method start.
@Override
public final void start(Config config) throws PersistenceException {
Workspace workspace = config.getWorkspace();
workspace.getRunner().start(workspace);
Runnable job = workspace.getRunner().getRunnable(config);
ScheduleOptions options = workspace.getRunner().getOptions(config);
if (options != null) {
scheduler.schedule(job, options);
} else {
job.run();
}
workspace.commit();
}
Aggregations