private static JobConfig getJobConfig(final Long subscriptionId, final Schedule schedule) { return JobConfig.forJobRunnerKey(JobRunnerKey.of(JOB_RUNNER_KEY)) .withSchedule(schedule) .withParameters(ImmutableMap.<String, Serializable>of(SUBSCRIPTION_IDENTIFIER, subscriptionId)); }
private void scheduleLogScanJob(Schedule schedule) { try { schedulerService.scheduleJob(JOB_ID, JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RunMode.RUN_ONCE_PER_CLUSTER) .withSchedule(schedule)); } catch (SchedulerServiceException e) { log.error("Failed to schedule log scan job", e); } } }
@Override public void afterPropertiesSet() throws Exception { schedulerService.registerJobRunner(CLEANUP_JOB_RUNNER_KEY, newCleanupTask()); // schedule the cleanup job once a day starting in a day schedulerService.scheduleJob(CLEANUP_JOB_ID, JobConfig.forJobRunnerKey(CLEANUP_JOB_RUNNER_KEY) .withSchedule(Schedule.forInterval(TimeUnit.DAYS.toMillis(1), DateTime.now().plusDays(1).toDate())) .withRunMode(RunMode.RUN_LOCALLY)); // cache dir is local to every application node }
private void queueDelayedEvent(final JiraHomeChangeEvent event) { delayedFileReplicationQueue.add(event); JobConfig jobConfig = JobConfig.forJobRunnerKey(DELAYED_REPLICATION_KEY) .withRunMode(RunMode.RUN_LOCALLY) .withSchedule(Schedule.runOnce(DateTime.now().plusSeconds(IDLE_SECONDS).toDate())); try { schedulerService.scheduleJob(DELAYED_REPLICATION_ID, jobConfig); } catch (SchedulerServiceException e) { log.error("Failed to schedule delayed replication", e); } }
@Override public void afterPropertiesSet() throws Exception { schedulerService.registerJobRunner(CLEANUP_JOB_RUNNER_KEY, newCleanupTask()); // schedule the cleanup job once a day starting in a day schedulerService.scheduleJob(CLEANUP_JOB_ID, JobConfig.forJobRunnerKey(CLEANUP_JOB_RUNNER_KEY) .withSchedule(Schedule.forInterval(TimeUnit.DAYS.toMillis(1), DateTime.now().plusDays(1).toDate())) .withRunMode(RunMode.RUN_LOCALLY)); // cache dir is local to every application node }
@Override public void onStart() { scheduler.registerJobRunner(JOB_RUNNER_KEY, this); try { scheduler.scheduleJob(JOB_ID, JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withSchedule(getSchedule())); } catch (final SchedulerServiceException e) { log.error("Unable to schedule analytics job", e); } }
@Override public void onStart() { schedulerService.registerJobRunner(JOB_RUNNER_KEY, this); JobConfig config = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RUN_ONCE_PER_CLUSTER) .withSchedule(Schedule.forInterval(REMOVE_INTERVAL, new Date(System.currentTimeMillis() + REMOVE_INTERVAL))); try { schedulerService.scheduleJob(JobId.of(JOB_ID), config); } catch (SchedulerServiceException e) { log.error("Unable to schedule expired session remover job", e); } }
@Override public void onStart() { long intervalInMillis = configuration.getAlertTruncationInterval().toMillis(); long firstRunTime = System.currentTimeMillis() + intervalInMillis; schedulerService.registerJobRunner(JOB_RUNNER_KEY, new TruncateAlertsJobRunner()); try { schedulerService.scheduleJob(JOB_ID, JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withSchedule(Schedule.forInterval(intervalInMillis, new Date(firstRunTime))) .withRunMode(RunMode.RUN_ONCE_PER_CLUSTER)); } catch (SchedulerServiceException e) { log.warn("Failed to schedule periodic alert truncation", e); } }
@Override public void start() throws Exception { final SchedulerService scheduler = ComponentAccessor.getComponent(SchedulerService.class); scheduler.registerJobRunner(JOB_RUNNER_KEY, this); // we need to scatter a bit sending events to analytics system, // lets not start this service on every instance in the same moment final Date firstRun = Date.from(Instant.now().plusMillis(random.nextLong() % FOUR_HOURS)); final JobConfig jobConfig = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RunMode.RUN_LOCALLY) .withSchedule(Schedule.forInterval(RUN_INTERVAL, firstRun)); scheduler.scheduleJob(JOB_ID, jobConfig); }
@Override public void triggerPoll(final long directoryID, final SynchronisationMode synchronisationMode) { JobConfig config = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RUN_ONCE_PER_CLUSTER) .withSchedule(Schedule.runOnce(null)) .withParameters(ImmutableMap.<String, Serializable>of("DIRECTORY_ID", directoryID)); try { schedulerService.scheduleJobWithGeneratedId(config); } catch (SchedulerServiceException e) { throw new RuntimeException(e); } }
/** * Request a full replication of files in the home directories that are configured for replication. */ public void replicateJiraHome() throws SchedulerServiceException { JobConfig jobConfig = JobConfig.forJobRunnerKey(FULL_REPLICATION_KEY) .withRunMode(RunMode.RUN_ONCE_PER_CLUSTER) .withSchedule(Schedule.runOnce(null)); schedulerService.scheduleJob(FULL_REPLICATION_ID, jobConfig); }
@Nullable private JobRunnerResponse validateJobConfig() { try { jobConfig = JobConfig.forJobRunnerKey(jobDetails.getJobRunnerKey()) .withRunMode(jobDetails.getRunMode()) .withSchedule(jobDetails.getSchedule()) .withParameters(jobDetails.getParameters()); return null; } catch (SchedulerRuntimeException sre) { return aborted(jobDetails.toString()); } }
@Override public void runNow(final long serviceId) throws Exception { JiraServiceContainer jiraServiceContainer = getServiceWithId(serviceId); if (jiraServiceContainer == null) { throw new ServiceException("Service with id '" + serviceId + "' was not found"); } JobConfig config = JobConfig.forJobRunnerKey(SERVICE_JOB_KEY) .withSchedule(Schedule.runOnce(null)) .withRunMode(RunMode.RUN_ONCE_PER_CLUSTER) .withParameters(ImmutableMap.<String, Serializable>of(SERVICE_ID_KEY, serviceId)); JobId jobId = schedulerService.scheduleJobWithGeneratedId(config); LOG.debug("JIRA Service '" + jiraServiceContainer.getName() + "' scheduled for immediate execution with job id '" + jobId + '\''); }
@EventListener public void onFrameworkStarted(PluginFrameworkStartedEvent event) { schedulerService.registerJobRunner(JOB_RUNNER_KEY, new AlertAnalyticsJobRunner()); try { schedulerService.scheduleJob(JOB_ID, JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withSchedule(Schedule.forCronExpression("0 19 * * * ?")) // collect stats daily at 00:19 .withRunMode(RunMode.RUN_ONCE_PER_CLUSTER)); } catch (SchedulerServiceException e) { log.warn("Failed to schedule daily alert analytics publishing job", e); } }
@Override public void start() throws Exception { SchedulerService scheduler = ComponentAccessor.getComponent(SchedulerService.class); scheduler.registerJobRunner(JOB_RUNNER_KEY, this); final JobConfig jobConfig = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RunMode.RUN_LOCALLY) .withSchedule(Schedule.forInterval(FIVE_MINUTES, null)); scheduler.scheduleJob(JOB_ID, jobConfig); }
@Override public void addPoller(final DirectoryPoller poller) throws DirectoryMonitorRegistrationException { final Date oneMinuteFromNow = new DateTime().plusMinutes(1).toDate(); final JobConfig config = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RUN_ONCE_PER_CLUSTER) .withSchedule(Schedule.forInterval(poller.getPollingInterval() * 1000, oneMinuteFromNow)) .withParameters(ImmutableMap.<String, Serializable>of(DIRECTORY_ID, poller.getDirectoryID())); try { schedulerService.scheduleJob(getJobId(poller), config); } catch (SchedulerServiceException e) { throw new DirectoryMonitorRegistrationException(e); } }
@Override public void start() throws Exception { final SchedulerService scheduler = ComponentAccessor.getComponent(SchedulerService.class); scheduler.registerJobRunner(JOB_RUNNER_KEY, this); final JobConfig jobConfig = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withRunMode(RunMode.RUN_LOCALLY) .withSchedule(Schedule.forInterval(DAILY, null)); scheduler.scheduleJob(JOB_ID, jobConfig); } }
private void scheduleSimpleJob(final JiraServiceContainer jiraServiceContainer) throws SchedulerServiceException { // Work out the fire time delay. Date nextFireTime = null; long lastRunMillis = jiraServiceContainer.getLastRun(); final long nextRunMillis = lastRunMillis > 0 ? lastRunMillis + jiraServiceContainer.getDelay() : System.currentTimeMillis(); final boolean localService = jiraServiceContainer.isLocalService(); if (nextRunMillis > System.currentTimeMillis()) { nextFireTime = new Date(nextRunMillis); } JobConfig config = JobConfig.forJobRunnerKey(SERVICE_JOB_KEY) .withSchedule(Schedule.forInterval(jiraServiceContainer.getDelay(), nextFireTime)) .withRunMode(localService ? RunMode.RUN_LOCALLY : RunMode.RUN_ONCE_PER_CLUSTER) .withParameters(ImmutableMap.<String, Serializable>of(SERVICE_ID_KEY, jiraServiceContainer.getId())); schedulerService.scheduleJob(toJobId(jiraServiceContainer.getId()), config); }
@Override protected void startHeartbeat() throws SchedulerServiceException { super.startHeartbeat(); //Initially run explicitly to get the first run out immediately SharedHomeFileWriterJobRunner runner = new SharedHomeFileWriterJobRunner(); runner.writeFile(); schedulerService.registerJobRunner(SHARED_HOME_FILE_WRITER_JOB_RUNNER_KEY, runner); JobConfig jobConfig = JobConfig.forJobRunnerKey(SHARED_HOME_FILE_WRITER_JOB_RUNNER_KEY) .withRunMode(RunMode.RUN_LOCALLY) .withSchedule(Schedule.forInterval(TimeUnit.MINUTES.toMillis(1), null)); schedulerService.scheduleJob(JobId.of(SHARED_HOME_FILE_WRITER_JOB_RUNNER_KEY_NAME), jobConfig); }
private void scheduleCronJob(final JiraServiceContainer jiraServiceContainer) throws SchedulerServiceException { final boolean localService = jiraServiceContainer.isLocalService(); JobConfig config = JobConfig.forJobRunnerKey(SERVICE_JOB_KEY) .withSchedule(Schedule.forCronExpression(jiraServiceContainer.getCronExpression())) .withRunMode(localService ? RunMode.RUN_LOCALLY : RunMode.RUN_ONCE_PER_CLUSTER) .withParameters(ImmutableMap.<String, Serializable>of(SERVICE_ID_KEY, jiraServiceContainer.getId())); schedulerService.scheduleJob(toJobId(jiraServiceContainer.getId()), config); }