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?
Community moderators have prevented the ability to post new answers.
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.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Me too. Not fixed on JIRA 6.0.x :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same issue here..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the interval is less than 1 min, it uses 1 min as default. If not it uses correct interval e.g 5 min
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using jira 5.1 and no luck with me :-(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
by the way, I do not get the difference of this code and one in the atlasian sal tutorial.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.