This page last changed on Jan 17, 2007 by jnolen.
Job plugin modules are available in Confluence 2.2 and later.

Job plugin modules enable you to add repeatable tasks to Confluence, which are in turn scheduled by Trigger Plugins.

Job Plugin Module

The Job plugin module adds a simple reusable component within a plugin. At a minimum, the module class must implement Quartz's Job interface, but for access to Confluence's objects and database you should extend com.atlassian.quartz.jobs.AbstractJob. Jobs are scheduled with Trigger Plugins.

Note that at the moment Jobs are not autowired by Spring.

Here is an example atlassian-plugin.xml fragment containing a single Job module:

<atlassian-plugin name="Sample Component" key="confluence.extra.component">
    ...
    <job key="myJob"
          name="My Job"
          class="com.example.myplugin.jobs.MyJob" />
    ...
</atlassian-plugin>
  • the name attribute represents how this component will be referred to in the Confluence interface.
  • the key attribute represents the internal, system name for your Job. This is what the Trigger will refer to.
  • the class attribute represents the class of the Job to be created. The class must have a no-argument constructor, or it will not be able to be instantiated by Confluence.

For examples of how to schedule Jobs to be run, see Trigger Plugins.

Note that in Confluence 2.3 you can also use a Spring Plugin as a job. This allows you to inject other Spring components into the Job, via the "jobDataAsMap" property of the job. An example is shown below. You cannot do this in Confluence 2.2.

Plugins containing Spring JobDetailBeans can't be dynamcally loaded at present, due to classloading issues.

<spring name="Space Cleaner Job" key="spaceCleanerJob" id="spaceCleanerJob" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="name">
            <value>Space Cleaner Job</value>
        </property>
        <property name="jobClass">
            <value>com.atlassian.confluence.extras.spacecleaner.SpaceCleanerJob</value>
        </property>
        <property name="jobDataAsMap">
            <map>
                <entry key="spaceManager"> <!-- these spring beans will be injected into the SpaceCleanerJob instance -->
                    <ref bean="spaceManager"/>
                </entry>
                <entry key="pageManager">
                    <ref bean="pageManager"/>
                </entry>
                <entry key="settingsManager">
                    <ref bean="settingsManager"/>
                </entry>
                <entry key="trashManager">
                    <ref bean="trashManager"/>
                </entry>
                <entry key="runOncePerCluster">
                     <value>true</value>
                 </entry>
            </map>
        </property>
    </spring>
    <trigger key="com.atlassian.confluence.extras.spacecleaner.SpaceCleanerJob.trigger" name="Space Cleaner Trigger">
        <job key="spaceCleanerJob" />
        <schedule cron-expression="0 * * * * ?" />     
    </trigger>

Will it be possible to have a <spring> component in an uploaded plugin in 2.3? Currently, this doesn't work - Spring complains about not being able to find the class from the plugin jar file.

Posted by david@randombits.org at Nov 26, 2006 22:43

Are you referring to CONF-7311 ?

Posted by jnolen at Nov 30, 2006 18:12

Yeah, that looks like the same symptoms. I'll put any comments there from now on...

Posted by david@randombits.org at Nov 30, 2006 18:20

My client is using Confluence 2.2.9.  I need to write a Job for them.  I understand that there is no Spring Auto Wire avalable; however, is there any way to access itmes such as userAccessor? (A way to circumvent Spring Auto Wiring?)

Posted by patrick.j.hill@gmail.com at Dec 07, 2006 18:36

If it isn't autowired then you want to use the ContainerManager static methods.

DOC:How do I get a reference to a component?

Posted by dhardiker@adaptavist.com at Dec 08, 2006 03:40
Document generated by Confluence on Mar 22, 2007 21:00