Class ClusterAwareJob

java.lang.Object
com.atlassian.bamboo.quartz.cluster.ClusterAwareJob
All Implemented Interfaces:
org.quartz.Job
Direct Known Subclasses:
AgentsHeartBeatCheckerJob, BranchDetectionJob, BranchExpiryJob, BuildMonitorJobScheduler, BuildQueueMonitorJobScheduler, CrowdDeletedEntityCleanupJob, DeletionServiceJob, ElasticInstanceScheduleJob, EphemeralAgentCleanupJob, ExpirySchedulerImpl.ExpiryJob, ManagedAgentContainersMonitorJob, OfflineElasticAgentsRemovalJob, OfflineRemoteAgentsRemovalJob, OrphanedBuildMonitorJob, OrphanedBuildResultRemovalJob, PerformanceStatsDispatchJob, PlanVcsRevisionHistoryCleanupScheduler.PlanVcsHistoryCleanupJob, PullRequestDetectionJob, RememberMeTokenExpiryJob, RemoveOrphanedSpecsStateJob, RemoveOrphanedTestCaseJob, RemovePullRequestsJob, RepositoryStoredSpecsPollingJob, ScheduledBackupJob, StaleAvatarsRemovalJob, SystemInfoJob, TagDetectionJob, VariableContextUpgradeJob

public abstract class ClusterAwareJob extends Object implements org.quartz.Job
ClusterAwareJob is an abstract base class for implementing background quartz jobs that need to run in a clustered environment.

Any job inheriting from this class should implement the executeBody and executionMode methods to define its specific logic and execution requirements. This class was created to centralize the handling of clustered job execution by leveraging cluster locks and node primary status. There are three modes: 1. LOCAL - schedules the job on every node in the cluster 2. PRIMARY - schedules the job on the primary node only, regardless of other nodes in the cluster 3. CLUSTERED - ensures that only one node executes the job at any given time and prevents concurrent execution across nodes, while also allowing seamless takeover when secondary nodes join the cluster.

  • Field Details

    • SCHEDULED_DURATION_BETWEEN_EXECUTIONS_SECONDS_CONST

      public static final String SCHEDULED_DURATION_BETWEEN_EXECUTIONS_SECONDS_CONST
      See Also:
    • SCHEDULED_DURATION_BETWEEN_EXECUTIONS_CRON_CONST

      public static final String SCHEDULED_DURATION_BETWEEN_EXECUTIONS_CRON_CONST
      See Also:
  • Constructor Details

  • Method Details

    • execute

      public final void execute(org.quartz.JobExecutionContext jobExecutionContext) throws org.quartz.JobExecutionException
      Specified by:
      execute in interface org.quartz.Job
      Throws:
      org.quartz.JobExecutionException
    • getDurationBetweenExecutionsInSeconds

      @VisibleForTesting protected long getDurationBetweenExecutionsInSeconds(org.quartz.JobExecutionContext jobExecutionContext, String jobIdentifier)
    • extractDurationBetweenExecutionsSeconds

      @VisibleForTesting protected Optional<Long> extractDurationBetweenExecutionsSeconds(@NotNull @NotNull String cronExpressionStr)
    • executeBody

      protected abstract void executeBody(org.quartz.JobExecutionContext jobExecutionContext) throws org.quartz.JobExecutionException
      This is the job real work to be performed. Every job that is based on this parent cluster aware job needs to implement this method and place here stuff that would be normally put in #execute(JobExecutionContext)
      Throws:
      org.quartz.JobExecutionException
    • executionMode

      protected abstract JobExecutionMode executionMode()
      Determines the execution mode for this job.

      The execution mode defines how this job should execute in a clustered environment. Implementations should return the appropriate mode based on their execution requirements (e.g., LOCAL, PRIMARY, or CLUSTERED).