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); } } }
@Nonnull @Override public Map<String, Serializable> getParameters() { return config.getParameters(); }
@Nonnull @Override public RunMode getRunMode() { return config.getRunMode(); }
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)); }
@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); } }
@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); } }
public Trigger buildTrigger(final JobId jobId, final JobConfig jobConfig) throws SchedulerServiceException { final byte[] parameters = parameterMapSerializer.serializeParameters(jobConfig.getParameters()); final Trigger trigger = buildTrigger(jobConfig.getSchedule()); trigger.setGroup(QUARTZ_TRIGGER_GROUP); trigger.setName(jobId.toString()); trigger.getJobDataMap().put(QUARTZ_PARAMETERS_KEY, parameters); return trigger; }
@Override public void scheduleJob(final JobId jobId, final JobConfig jobConfig) throws SchedulerServiceException { try { requireNonNull(jobConfig, "jobConfig"); LOG.debug("scheduleJob: {}: {}", jobId, jobConfig); localJobs.unscheduleJob(jobId); clusteredJobs.unscheduleJob(jobId); final Quartz1SchedulerFacade facade = getFacade(jobConfig.getRunMode()); final JobRunnerKey jobRunnerKey = jobConfig.getJobRunnerKey(); final Trigger trigger = triggerFactory.buildTrigger(jobId, jobConfig); facade.scheduleJob(jobRunnerKey, trigger); } catch (SchedulerRuntimeException sre) { throw checked(sre); } }
@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 @Nonnull public Status scheduleDelayedUpgrades(final int delayMins, final boolean isAllowReindex) { final Schedule schedule = Schedule.runOnce(DateTime.now().plusMinutes(delayMins).toDate()); JobConfig jobConfig = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withSchedule(schedule) .withParameters(ImmutableMap.<String, Serializable>of(REINDEX_ALLOWED_PROPERTY, isAllowReindex)); try { schedulerService.scheduleJob(JOB_ID, jobConfig); } catch (SchedulerServiceException e) { log.error( "Unable to schedule upgrade tasks for future execution :" + e, e); final Collection<String> errors = ImmutableList.of( "Unable to schedule upgrade tasks for future execution: " + e.getMessage() + '\n' + ExceptionUtils.getStackTrace(e)); return new Status(errors); } return Status.OK; }
/** * 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); }
@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 + '\''); }
private boolean isReindexAllowed(final JobRunnerRequest jobRunnerRequest) { Boolean isReindexAllowed = (Boolean) jobRunnerRequest.getJobConfig().getParameters().get(REINDEX_ALLOWED_PROPERTY); // If no parameter is found we assume reindex is allowed. return isReindexAllowed == null ? true : isReindexAllowed; }
private StreamsEntryRequest createStreamsEntryRequest(JobRunnerRequest request) { final DateTime startTime = new DateTime(request.getStartTime()); final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_PATTERN); return new StreamsEntryRequest() .id(startTime.hashCode()) .title("triggered as per " + request.getJobConfig().getRunMode() + " job, at " + dateFormatter.format(request.getStartTime())) .postedDate(startTime.plusMinutes(2)) .type(ActivityObjectTypes.article()) .verb(ActivityVerbs.post()) .user("Scheduler"); } }
@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 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); }
@Nullable @Override public JobRunnerResponse runJob(final JobRunnerRequest jobRunnerRequest) { // Get the job class to actually run final Map<String,Serializable> parameters = jobRunnerRequest.getJobConfig().getParameters(); final Long serviceId = (Long) parameters.get(ServiceManager.SERVICE_ID_KEY); if (serviceId == null) { return JobRunnerResponse.failed("Service entry with job ID '" + jobRunnerRequest.getJobId() + "' has no job config parameters"); } return runServiceId(serviceId); }
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 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); } }
@SuppressWarnings("unchecked") @Nullable @Override public JobRunnerResponse runJob(final JobRunnerRequest request) { final Map<String, Serializable> params = request.getJobConfig().getParameters(); try { final Class<? extends PluginJob> jobClass = (Class<? extends PluginJob>) classLoader.loadClass((String) params.get(JOB_CLASS_CANONICAL_NAME)); jobClass.newInstance().execute(jobDataMap); return JobRunnerResponse.success(); } catch (Exception e) { log.error(String.format("Unable to execute the job [id:%s]", request.getJobId().toString()), e); return JobRunnerResponse.failed(e); } } }