Class ScheduleUtil
- java.lang.Object
-
- com.atlassian.confluence.schedule.ScheduleUtil
-
public class ScheduleUtil extends Object
A general utility class for scheduling.- Since:
- 5.10
-
-
Field Summary
Fields Modifier and Type Field Description static com.atlassian.scheduler.config.JobIdBACKUP_JOB_IDstatic StringSCHEDULER_FLUSH_TIMEOUT_SECONDS_PROPERTY_NAMEThe customer can set the value of this property to override the default timeout value - 2 minutes.
-
Constructor Summary
Constructors Constructor Description ScheduleUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @Nullable DatecalculateNextRunTime(com.atlassian.scheduler.SchedulerService schedulerService, com.atlassian.scheduler.config.JobConfig jobConfig, @Nullable Date thisRunTime)As Javadoc of SchedulerService#calculateNextRunTime says, for interval job the result may not be correct, so we calculate by ourselves.static com.atlassian.scheduler.config.JobIdgenerateUniqueJobId(com.atlassian.scheduler.SchedulerService schedulerService, String idPrefix)Instead of usingSchedulerService.scheduleJobWithGeneratedId(com.atlassian.scheduler.config.JobConfig), you can useSchedulerService.scheduleJob(com.atlassian.scheduler.config.JobId, com.atlassian.scheduler.config.JobConfig)with the result of this method.static intgetJitterSecs(Map<String,Serializable> parameters)static com.atlassian.scheduler.config.JobConfiggetJobConfig(ScheduledJobConfiguration configuration, ManagedScheduledJob job, TimeZone timeZone)BuildsJobConfigfrom info inconfiguration, with fallback info fromjob.static intgetRepeatCount(Map<String,Serializable> parameters)static longgetSchedulerFlushTimeout()static longgetUnscheduleJobAfterTimestampMillis(Map<String,Serializable> parameters)static booleanisBackupEnabled(ScheduledJobManager scheduledJobManager, SettingsManager settingsManager)Determines if the backup job is enabled.static voidpauseAndFlushSchedulerService(com.atlassian.scheduler.core.LifecycleAwareSchedulerService schedulerService)If there's error, it will be wrapped in aSchedulerServiceException.static voidshutdownAndFlushSchedulerService(com.atlassian.scheduler.core.LifecycleAwareSchedulerService schedulerService)If there's error, it will be wrapped in aSchedulerServiceException.static com.atlassian.scheduler.config.JobConfigwithCronSchedule(com.atlassian.scheduler.config.JobConfig jobConfig, @Nullable String cronExpression, TimeZone timeZone)Returns a newJobConfigwith the newcronExpressionand time zone if its schedule is of typeCRON_EXPRESSIONand the time zone has changed.static Map<String,Serializable>withJitterSecs(int jitterSecs)atlassian-scheduler doesn't support schedule jittering.static Map<String,Serializable>withJitterSecs(Map<String,Serializable> parameters, int jitterSecs)atlassian-scheduler doesn't support schedule jittering.static Map<String,Serializable>withoutJitterSecs(Map<String,Serializable> parameters)static com.atlassian.scheduler.config.JobConfigwithTimeZone(com.atlassian.scheduler.config.JobConfig jobConfig, TimeZone timeZone)Returns a newJobConfigwith the specified time zone if its schedule is of typeCRON_EXPRESSIONand the time zone has changed.static Map<String,Serializable>withUnscheduleJobAfterTimestampMillis(long repeatInterval, int repeatCount, @Nullable Date firstRunTime)atlassian-scheduler interval jobs don't support repeat count.static Map<String,Serializable>withUnscheduleJobAfterTimestampMillis(Map<String,Serializable> parameters, long repeatInterval, int repeatCount, @Nullable Date firstRunTime)atlassian-scheduler doesn't support repeat count.
-
-
-
Field Detail
-
BACKUP_JOB_ID
public static final com.atlassian.scheduler.config.JobId BACKUP_JOB_ID
-
SCHEDULER_FLUSH_TIMEOUT_SECONDS_PROPERTY_NAME
public static final String SCHEDULER_FLUSH_TIMEOUT_SECONDS_PROPERTY_NAME
The customer can set the value of this property to override the default timeout value - 2 minutes.- See Also:
- Constant Field Values
-
-
Method Detail
-
isBackupEnabled
public static boolean isBackupEnabled(ScheduledJobManager scheduledJobManager, SettingsManager settingsManager)
Determines if the backup job is enabled.
-
calculateNextRunTime
public static @Nullable Date calculateNextRunTime(com.atlassian.scheduler.SchedulerService schedulerService, com.atlassian.scheduler.config.JobConfig jobConfig, @Nullable Date thisRunTime) throws com.atlassian.scheduler.SchedulerServiceException
As Javadoc of SchedulerService#calculateNextRunTime says, for interval job the result may not be correct, so we calculate by ourselves.- Returns:
nullif repeat count reached- Throws:
com.atlassian.scheduler.SchedulerServiceException
-
generateUniqueJobId
public static com.atlassian.scheduler.config.JobId generateUniqueJobId(com.atlassian.scheduler.SchedulerService schedulerService, String idPrefix) throws com.atlassian.scheduler.SchedulerServiceExceptionInstead of usingSchedulerService.scheduleJobWithGeneratedId(com.atlassian.scheduler.config.JobConfig), you can useSchedulerService.scheduleJob(com.atlassian.scheduler.config.JobId, com.atlassian.scheduler.config.JobConfig)with the result of this method.- Throws:
com.atlassian.scheduler.SchedulerServiceException
-
pauseAndFlushSchedulerService
public static void pauseAndFlushSchedulerService(com.atlassian.scheduler.core.LifecycleAwareSchedulerService schedulerService) throws com.atlassian.scheduler.SchedulerServiceExceptionIf there's error, it will be wrapped in aSchedulerServiceException.- Throws:
com.atlassian.scheduler.SchedulerServiceException
-
shutdownAndFlushSchedulerService
public static void shutdownAndFlushSchedulerService(com.atlassian.scheduler.core.LifecycleAwareSchedulerService schedulerService) throws com.atlassian.scheduler.SchedulerServiceExceptionIf there's error, it will be wrapped in aSchedulerServiceException.- Throws:
com.atlassian.scheduler.SchedulerServiceException
-
getSchedulerFlushTimeout
public static long getSchedulerFlushTimeout()
-
withJitterSecs
public static Map<String,Serializable> withJitterSecs(int jitterSecs)
atlassian-scheduler doesn't support schedule jittering. We encode jitterSecs inJobConfigparameters.
-
withJitterSecs
public static Map<String,Serializable> withJitterSecs(Map<String,Serializable> parameters, int jitterSecs)
atlassian-scheduler doesn't support schedule jittering. We encode jitterSecs inJobConfigparameters.
-
getJitterSecs
public static int getJitterSecs(Map<String,Serializable> parameters)
-
withoutJitterSecs
public static Map<String,Serializable> withoutJitterSecs(Map<String,Serializable> parameters)
-
withUnscheduleJobAfterTimestampMillis
public static Map<String,Serializable> withUnscheduleJobAfterTimestampMillis(long repeatInterval, int repeatCount, @Nullable Date firstRunTime)
atlassian-scheduler interval jobs don't support repeat count. We encode repeat count as the timestamp to unschedule in JobConfig parameters: unschedule timestamp = firstRunTime (or now) + repeatInterval x repeatCount
-
withUnscheduleJobAfterTimestampMillis
public static Map<String,Serializable> withUnscheduleJobAfterTimestampMillis(Map<String,Serializable> parameters, long repeatInterval, int repeatCount, @Nullable Date firstRunTime)
atlassian-scheduler doesn't support repeat count. We encode repeat count as the timestamp to unschedule the job in JobConfig parameters: unschedule timestamp = firstRunTime (or now) + repeatInterval x repeatCount
-
getUnscheduleJobAfterTimestampMillis
public static long getUnscheduleJobAfterTimestampMillis(Map<String,Serializable> parameters)
-
getRepeatCount
public static int getRepeatCount(Map<String,Serializable> parameters)
-
withTimeZone
public static com.atlassian.scheduler.config.JobConfig withTimeZone(com.atlassian.scheduler.config.JobConfig jobConfig, TimeZone timeZone)Returns a newJobConfigwith the specified time zone if its schedule is of typeCRON_EXPRESSIONand the time zone has changed.
-
withCronSchedule
public static com.atlassian.scheduler.config.JobConfig withCronSchedule(com.atlassian.scheduler.config.JobConfig jobConfig, @Nullable String cronExpression, TimeZone timeZone)Returns a newJobConfigwith the newcronExpressionand time zone if its schedule is of typeCRON_EXPRESSIONand the time zone has changed. If the newcronExpressionisnull, only the time zone is changed if it has changed.
-
getJobConfig
public static com.atlassian.scheduler.config.JobConfig getJobConfig(ScheduledJobConfiguration configuration, ManagedScheduledJob job, TimeZone timeZone)
BuildsJobConfigfrom info inconfiguration, with fallback info fromjob.
-
-