Search in sources :

Example 16 with ScheduleOptions

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);
    }
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionException(org.apache.sling.distribution.common.DistributionException) LoginException(org.apache.sling.api.resource.LoginException)

Example 17 with ScheduleOptions

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);
}
Also used : DistributionRequestHandler(org.apache.sling.distribution.trigger.DistributionRequestHandler) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) ResourceResolverFactory(org.apache.sling.api.resource.ResourceResolverFactory) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Test(org.junit.Test)

Example 18 with ScheduleOptions

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() });
        }
    }
}
Also used : Serializable(java.io.Serializable) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) ScheduleInfoImpl(org.apache.sling.event.impl.support.ScheduleInfoImpl) HashMap(java.util.HashMap) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo)

Example 19 with ScheduleOptions

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;
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions)

Example 20 with ScheduleOptions

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();
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) Workspace(com.adobe.acs.commons.workflow.bulk.execution.model.Workspace)

Aggregations

ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)21 Scheduler (org.apache.sling.commons.scheduler.Scheduler)8 Test (org.junit.Test)7 File (java.io.File)4 Date (java.util.Date)3 DistributionQueueProcessor (org.apache.sling.distribution.queue.DistributionQueueProcessor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LoginException (org.apache.sling.api.resource.LoginException)2 DistributionException (org.apache.sling.distribution.common.DistributionException)2 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)2 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)2 DistributionRequestHandler (org.apache.sling.distribution.trigger.DistributionRequestHandler)2 Workspace (com.adobe.acs.commons.workflow.bulk.execution.model.Workspace)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1