How does Atlassian Scheduler work?

Hello,

for my jira plugin, I need a cron scheduler that can execute a task on a fixed rate. There are various tutorials. The problem is, that everything I found in the internet has deprecated methods and classes such as PluginJob. It says to use Atlassian Scheduler instead. But how to use it? i have no clue, at all and the documentation is not enough for me to understand it. I’d like to have an example…

Here’s minimal example of Atlassian Scheduler usage.
Although in case you have only one job and no more are expected, it may make sense to combine PluginStateListener and UpdateSomethingScheduler in one class, because in my example UpdateSomethingScheduler extends PluginStateListener.

1 Like

Wow, thank you so so much! I’m going to try it now and will update you in a few days how it worked.What dependency did you use for the spring imports? And could you also share your Const class or how to retrieve the APP_KEY?
:slight_smile:

<dependency>
    <groupId>com.atlassian.plugin</groupId>
    <artifactId>atlassian-spring-scanner-annotation</artifactId>
    <version>${atlassian.spring.scanner.version}</version>
    <scope>provided</scope>
</dependency>

See Atlassian Spring Scanner

Const.APP_KEY is just a string. “groupId.artifactId” from pom.xml.

Thank you, I actually had that exact thing in my pom,xml, but java still seems to not recognize these imports. Is it because of the Atlassian version?

You mean compile time, or IDE highlighting? Anyways, you have to carefully follow the setup instructions for Atlassian Spring Scanner to make it work.

IDE highlighting. I can’t import them, although I followed the instructions in bitbucket… jira version is 9.4.0

If you’re using Intellij Idea, check your Maven settings in the IDE. They should point exactly to Maven provided by the Atlassian SDK.

I use eclipse. My problem is that in the application context I get this error: Description Resource Path Location Type cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'atlassian-scanner:scan-indexes'.

for the scan-idexes line and

Description Resource Path Location Type Error while downloading 'http://www.atlassian.com/schema/atlassian-scanner/2/atlassian-scanner.xsd' to xx : '[java.io.FileNotFoundException] https://www.atlassian.com/schema/atlassian-scanner/2/atlassian-scanner.xsd with code: 404 Not Found'. plugin-context.xml

This is the file which I basically just copied from bitbucket

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner/2"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.atlassian.com/schema/atlassian-scanner/2
        http://www.atlassian.com/schema/atlassian-scanner/2/atlassian-scanner.xsd">
        <atlassian-scanner:scan-indexes/>
</beans>