/** * Wraps the provided string as a {@code JobId}. * * @param id the job ID, as a string * @return the wrapped job runner key */ public static JobId of(String id) { return new JobId(id); }
/** * Returns a copy of this job config that will use the specified schedule * instead of what it currently uses. * * @param schedule the new schedule; may be {@code null}, in which case the default * {@link Schedule#runOnce(Date) runOnce(new Date())} is used * @return the new job configuration; the original is left unchanged */ public JobConfig withSchedule(Schedule schedule) { return new JobConfig(jobRunnerKey, runMode, schedule, parameters); }
/** * Creates a new schedule for the given cron expression. The cron expression is not verified immediately, * but invalid expressions will cause {@link SchedulerService#scheduleJobWithGeneratedId(JobConfig)} to fail. The system's * {@link TimeZone#getDefault() default time zone} is assumed. * * @param cronExpression the cron expression to use for the schedule * @return a schedule for running jobs when the given cron expression is satisfied */ public static Schedule forCronExpression(String cronExpression) { return forCronExpression(cronExpression, null); }
@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); } }
/** * 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); }
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 Schedule getSchedule() { return Schedule.forInterval(SCHEDULE_INTERVAL, null); }
private static JobId toJobId(final Long subId) { return JobId.of(SUBSCRIPTION_PREFIX + ':' + subId); }
protected String getFrequencyName() { if (intervalMillis >= 0) { return frequencyToName(intervalMillis); } if (schedule == null || schedule.getIntervalScheduleInfo() == null) { return FREQUENCY_DAILY; } return frequencyToName(schedule.getIntervalScheduleInfo().getIntervalInMillis()); }
@SuppressWarnings("NullableProblems") // Guava should not have stuck @Nullable on this... @Override public JobRunnerKey apply(String jobName) { return JobRunnerKey.of(jobName); } });
@Override public JobRunnerKey apply(JobConfig config) { return config.getJobRunnerKey(); } };
/** * Creates a new schedule for the given cron expression. The cron expression is not verified immediately, * but invalid expressions will cause {@link SchedulerService#scheduleJobWithGeneratedId(JobConfig)} to fail. * * @param cronExpression the cron expression to use for the schedule * @param timeZone the time zone within which to apply the rules of the cron expression; may be {@code null} * to use a default time zone that is appropriate for the application * @return a schedule for running jobs when the given cron expression is satisfied */ public static Schedule forCronExpression(String cronExpression, @Nullable TimeZone timeZone) { return new Schedule(Type.CRON_EXPRESSION, null, new CronScheduleInfo(cronExpression, timeZone)); }
@Override public int compareTo(final JobRunnerWrapper o) { return getKey().compareTo(o.getKey()); } }
@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 static JobId toJobId(final Long subId) { return JobId.of(SUBSCRIPTION_PREFIX + ':' + subId); }
@Override public FilterSubscription createSubscription(final ApplicationUser user, final Long filterId, String groupName, final String cronExpression, final Boolean emailOnEmpty) { Schedule schedule = Schedule.forCronExpression(cronExpression); return createSubscription(user, filterId, groupName, emailOnEmpty, schedule); }
/** * Returns a copy of this job config that will use the specified run mode * instead of what it currently uses. * * @param runMode the new run mode; may be {@code null}, in which case the default * {@link RunMode#RUN_ONCE_PER_CLUSTER} is used * @return the new job configuration; the original is left unchanged */ public JobConfig withRunMode(RunMode runMode) { return new JobConfig(jobRunnerKey, runMode, schedule, parameters); }
@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); }
private JobId toJobId(final Long subId) { return JobId.of(DefaultSubscriptionManager.SUBSCRIPTION_PREFIX + ":" + subId); }