Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA SAL PluginScheduler ignores provided interval -always 1 minute

Juha Siltanen October 31, 2012

I am using a downloaded JIRA installation of version 5.0.2.

I've developed a JIRA plugin that runs scheduled and I am using the following configuration in my atlassian-plugin.xml to access scheduling capabilities:

<component-import key="pluginScheduler">
    <description>SAL Scheduler</description>
    <interface>com.atlassian.sal.api.scheduling.PluginScheduler</interface>

</component-import>

PluginScheduler.scheduleJob(...) is used for scheduling the plugin execution.

The interval in milliseconds that is provided to the scheduleJob method is completely ignored and the scheduler triggers every minute (the interval is fixed to be 1 minute).

How to get the scheduling to apply the provided interval parameter?

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

6 votes
Answer accepted
Juha Siltanen November 12, 2012

As per the tutorial provided by Atlassian, the recommended procedure for scheduling plugin executions is done via the PluginScheduler component in SAL. Please refer to this link for details:

https://developer.atlassian.com/display/DOCS/Plugin+Tutorial+-+Scheduling+Events+via+SAL

Furthermore, Atlassian has developed a plugin to expose JIRA instrumentation data via JMX. This plugin operates using scheduled executions.

https://marketplace.atlassian.com/plugins/com.atlassian.instrumentation.atlassian-instrumentation-expose-jmx

Regardless of the instructions provided, their own plugin does not conform to the scheduling recommendations they provide. Apparently Atlassian has discover the inadequacy of PluginScheduler (always fixed interval of 1 minute), because the JMX plugin does not use PluginScheduler but is reverting to basic java.util.concurrent.* classes with some helper classes by Atlassian.

This is one solution on how to schedule plugin executions on some other interval than 1 minute.

First you declare a Runnable instance that executes the desired operation.

Runnable jobExecution = new Runnable() {

			@SuppressWarnings("serial")
			@Override
			public void run() {
				myScheduledTask.execute(new HashMap<String,Object>() {{
                    put(KEY, MyMonitorImpl.this);
                }});
			}
        	
        };

Then you instantiate java.util.concurrent.ScheduledExecutorService (schedulerThread).

schedulerThread = MultiTenantExecutors.wrap(
				Executors.newSingleThreadScheduledExecutor(
						ThreadFactories.namedThreadFactory(
								"my-scheduled-plugin", 
								com.atlassian.util.concurrent.ThreadFactories.Type.DAEMON)));

Then you feed the Runnable instance to your ScheduledExecutorService.

schedulerThread.scheduleAtFixedRate(jobExecution, 10L, 3600L, TimeUnit.SECONDS);

And now you have a plugin that executes every 60 minutes.

Here are the Atlassian packages used.

<dependency>
			<groupId>com.atlassian.jira</groupId>
			<artifactId>atlassian-jira</artifactId>
			<version>5.0.2</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.atlassian.sal</groupId>
			<artifactId>sal-api</artifactId>
			<version>2.0.0</version>
			<scope>provided</scope>
		</dependency>

Here are some of the required imports for the solution.

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.atlassian.multitenant.juc.MultiTenantExecutors;
import com.atlassian.util.concurrent.ThreadFactories;
import com.atlassian.sal.api.lifecycle.LifecycleAware;

1 vote
overlight October 31, 2012

I have the same issue too.

Anton Reshetnikov April 15, 2013

I have the same trouble

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
July 8, 2013

Me too. Not fixed on JIRA 6.0.x :(

IshanL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 7, 2013

Same issue here..

0 votes
IshanL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 6, 2015

If the interval is less than 1 min, it uses 1 min as default. If not it uses correct interval e.g 5 min

0 votes
Maris Seimanovs November 28, 2013

It seems, interval is ignored only for first one-two runs - after that it starts running as expected. At least that's what I noticed on JIRA 6.1.3 when setting the interval to 5 minutes. But will not work if set the interval to less than a minute.

0 votes
Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 8, 2013

I did it this way and it works:

Date start = new Date();
Map<String, Object> params = new HashMap<String,Object>();
long interval = (3-1) * MINUTES_TO_MILLLIS

pluginScheduler.scheduleJob(
        JOB_NAME,                   // unique name of the job
        MonitorCollectJob.class,     // class of the job
        params,     // data that needs to be passed to the job
        start,           // the time the job is to start
        interval); 
}

This code will execute the job initially and after 1 minute.

Then the job is scheduled every 3 minutes.

IshanL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2013

I am using jira 5.1 and no luck with me :-(

IshanL
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2013

by the way, I do not get the difference of this code and one in the atlasian sal tutorial.

Paul Pasler
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 9, 2013

Your right :)

I had some troubles and tried many configurations, so I though it was different to the tutorial.

This whole SAL Scheduler thing doesn't work very good...

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events