Class JobConfigModuleDescriptor

java.lang.Object
com.atlassian.plugin.descriptors.AbstractModuleDescriptor<Void>
com.atlassian.confluence.plugins.scheduler.spi.descriptor.JobConfigModuleDescriptor
All Implemented Interfaces:
com.atlassian.plugin.ModuleDescriptor<Void>, com.atlassian.plugin.Resourced, com.atlassian.plugin.ScopeAware, com.atlassian.plugin.StateAware

@ParametersAreNonnullByDefault public final class JobConfigModuleDescriptor extends com.atlassian.plugin.descriptors.AbstractModuleDescriptor<Void>
Defines an atlassian-scheduler JobConfig within a plugin.

In atlassian-plugin.xml:

 
 <job-config name="My job" key="myJobId">
     <job key="myJobRunner" perClusterJob="true" clusteredOnly="true"/>
     <schedule cron-expression="0 * * * * ?" jitterSecs="10"/>
     <managed editable="true" keepingHistory="true" canRunAdhoc="true" canDisable="true" disabledByDefault="true"/>
 </job-config>
 
 

If using spring-scanner, ensure your job runner is defined as a spring bean with a @org.springframework.stereotype.Component or @javax.inject.Named annotation:

 
 @Component
 public class MyJobRunner implements JobRunner {
     ...
 }
 
 

If not using spring-scanner, then declare your component in atlassian-plugin.xml:

 
 <component key="myJobRunner" class="my.plugin.MyJobRunner"/>
 
 

Job runner classes must implement JobRunner.

schedule can be interval. This example repeats every hour (3600000 milliseconds) and only 5 times:

 
 <schedule repeat-interval="3600000" repeat-count="5" />
 
 

To repeat indefinitely, set repeat-count to -1, or omit it. repeat-count="0" means the job runs only once.

job-config:

  • name — represents how this job config will be referred to in the Confluence interface.
  • key — represents the internal, system name for the job.

job:

  • key - points to the JobRunner component.
  • perClusterJob - true indicates this job will only run once in a cluster rather than on every node.
  • clusteredOnly - optional, true indicates this job won't be scheduled in non-clustered environment.

schedule:

  • Either cron-expression or repeat-interval must present. repeat-count is optional in case of repeat-interval.
  • jitterSecs - optional, allows us to introduce some random jitter, this is only for On Demand environment use, to prevent many 1000s of servers from attempting to do similar things all at once, by providing a jitter value less than the size of the schedule frequency we spread the load caused by a process over time.

managed is optional, if omitted the job will not appear in the Scheduled Jobs administration page.

If any of these attributes are omitted, their values are assumed to be false:

  • editable — if true, the job's schedule can be edited, forced to false if schedule type is interval.
  • keepingHistory — if true, the job's history persists and survives server restarts; if false, the job's history is only stored in memory and will be lost upon the next server restart.
  • canRunAdhoc — if true, the job can be executed manually on the Scheduled Jobs administration screen.
  • canDisable — if true, the job can be enabled/disabled on the Scheduled Jobs administration screen.
  • disabledByDefault — if true, the job is disabled by default on the Scheduled Jobs administration screen.

Migration from <job> TriggerModuleDescriptor and <trigger> (JobModuleDescriptor):

  • For ease of use (see CONF-20162), there's nothing to replace <job>. Use <component> as above instead.
  • The XML of <job-config> is made to look similar to that of <trigger>, to make the migration from it easier.
  • For managed jobs, the key of <job-config> is used to lookup i18n job name (scheduledjob.desc.<key>), to display at the Confluence admin UI. Before, it's the key of <job>.
Since:
5.10.3
  • Field Summary

    Fields inherited from class com.atlassian.plugin.descriptors.AbstractModuleDescriptor

    key, moduleClass, moduleClassName, moduleFactory, name, plugin, resources
  • Constructor Summary

    Constructors
    Constructor
    Description
    JobConfigModuleDescriptor(com.atlassian.plugin.module.ModuleFactory moduleFactory, ManagedScheduledJobRegistrationService jobRegistrationService, com.atlassian.sal.api.timezone.TimeZoneManager timeZoneManager, ClusterManager clusterManager, com.atlassian.scheduler.SchedulerService schedulerService, com.atlassian.event.api.EventListenerRegistrar eventListenerRegistrar, com.atlassian.sal.api.lifecycle.LifecycleManager lifecycleManager, org.osgi.framework.BundleContext bundleContext)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    Plugins with unmanaged jobs must wait till application is started before being scheduled.
     
    void
    init(@NonNull com.atlassian.plugin.Plugin plugin, @NonNull com.atlassian.plugin.module.Element element)
     
    void
     
    void
    Do not use TenantArrivedEvent because it's fired before the DB migration Jobs may depend on DB prepared by the DB migration, see PluginFrameworkContextListener

    Methods inherited from class com.atlassian.plugin.descriptors.AbstractModuleDescriptor

    assertModuleClassImplements, checkPermissions, destroy, equals, getCompleteKey, getDescription, getDescriptionKey, getI18nNameKey, getKey, getMinJavaVersion, getModuleClass, getModuleClassName, getName, getParams, getPlugin, getPluginKey, getRequiredPermissions, getResourceDescriptor, getResourceDescriptors, getResourceLocation, getScopeKey, hashCode, isBroken, isEnabled, isEnabledByDefault, isSystemModule, loadClass, satisfiesMinJavaVersion, setBroken, setPlugin, toString, validate

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.atlassian.plugin.ModuleDescriptor

    getDisplayName
  • Constructor Details

    • JobConfigModuleDescriptor

      @Autowired public JobConfigModuleDescriptor(com.atlassian.plugin.module.ModuleFactory moduleFactory, ManagedScheduledJobRegistrationService jobRegistrationService, com.atlassian.sal.api.timezone.TimeZoneManager timeZoneManager, ClusterManager clusterManager, com.atlassian.scheduler.SchedulerService schedulerService, com.atlassian.event.api.EventListenerRegistrar eventListenerRegistrar, com.atlassian.sal.api.lifecycle.LifecycleManager lifecycleManager, org.osgi.framework.BundleContext bundleContext)
  • Method Details

    • listenApplicationStartedEvent

      @PostConstruct public void listenApplicationStartedEvent()
    • getModule

      public Void getModule()
      Specified by:
      getModule in interface com.atlassian.plugin.ModuleDescriptor<Void>
      Specified by:
      getModule in class com.atlassian.plugin.descriptors.AbstractModuleDescriptor<Void>
    • init

      public void init(@NonNull com.atlassian.plugin.Plugin plugin, @NonNull com.atlassian.plugin.module.Element element) throws com.atlassian.plugin.PluginParseException
      Specified by:
      init in interface com.atlassian.plugin.ModuleDescriptor<Void>
      Overrides:
      init in class com.atlassian.plugin.descriptors.AbstractModuleDescriptor<Void>
      Throws:
      com.atlassian.plugin.PluginParseException
    • onApplicationStartedEvent

      @EventListener public void onApplicationStartedEvent(ApplicationStartedEvent event)
      Do not use TenantArrivedEvent because it's fired before the DB migration Jobs may depend on DB prepared by the DB migration, see PluginFrameworkContextListener
    • enabled

      public void enabled()

      Plugins with unmanaged jobs must wait till application is started before being scheduled. See onApplicationStartedEvent(ApplicationStartedEvent)

      Additionally, managed jobs of plugins enabled at startup, must be registered immediately, otherwise the SchedulerService may malfunction, cause unknown.

      Specified by:
      enabled in interface com.atlassian.plugin.StateAware
      Overrides:
      enabled in class com.atlassian.plugin.descriptors.AbstractModuleDescriptor<Void>
    • disabled

      public void disabled()
      Specified by:
      disabled in interface com.atlassian.plugin.StateAware
      Overrides:
      disabled in class com.atlassian.plugin.descriptors.AbstractModuleDescriptor<Void>