View Javadoc

1   package com.atlassian.scheduler;
2   
3   import com.atlassian.annotations.PublicSpi;
4   import com.atlassian.scheduler.config.JobRunnerKey;
5   
6   import javax.annotation.Nullable;
7   
8   /**
9    * Invoked by the {@link SchedulerService} when it is time for a scheduled job to run.
10   * <p>
11   * Application code should register the JobRunner on startup, and need do nothing on shutdown.
12   * </p><p>
13   * Plugins should register the JobRunner implementation at startup/plugin enabled, and
14   * {@link SchedulerService#unregisterJobRunner(JobRunnerKey) unregister} the {@code JobRunner}
15   * when the plugin is disabled.
16   * </p>
17   */
18  @PublicSpi
19  public interface JobRunner {
20      /**
21       * Called by the {@link SchedulerService} when it is time for a job to run.
22       * The job is expected to perform its own error handling by catching exceptions
23       * as appropriate and reporting an informative message using
24       * {@link JobRunnerResponse#failed(String)}.
25       *
26       * @param request the information about the request that was supplied by the scheduler service
27       * @return a {@link JobRunnerResponse} providing additional detail about the result of running the job.
28       * The response is permitted to be {@code null}, which is treated as identical to
29       * {@link JobRunnerResponse#success()}.
30       */
31      @Nullable
32      JobRunnerResponse runJob(JobRunnerRequest request);
33  }