Scheduling via SAL does not give required output

Prameesha Samarakoon January 15, 2014

Hi,

I followed this ( https://developer.atlassian.com/display/DOCS/Scheduling+Events+via+SAL+Tutorial) tutorial and set up a scheduled task for my plug-in. Even though no error is identified in the logs, no output is printed either. I'm just printing a few lines to make sure the scheduling works fine.

Dependencies added to pom.xml

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

Modifications to atlassian-plugin.xml

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

<component key="SchedulerComponent" class="com.m.mn.RouterPluginPackage.RouterTaskImpl" system="true" public="true">
     	<description>The plug-in component that schedules the  router Task.</description>
     	<interface>com.atlassian.sal.api.lifecycle.LifecycleAware</interface>
    	<interface>com.m.mn.RouterPluginPackage.RouterScheduler</interface>
 </component>
The Task class..
import java.util.Date;
import java.util.Map;
import org.apache.log4j.Logger;

import com.atlassian.sal.api.scheduling.PluginJob;

public class RouterTask implements PluginJob{

	 private final Logger log = Logger.getLogger(RouterTask.class);
	 
	@Override
	public void execute(Map<String, Object> jobDataMap) {
		
		RouterTaskImpl taskImpl = (RouterTaskImpl) jobDataMap.get(RouterTaskImpl.KEY);
		log.info("Running Task");
		assert taskImpl != null;
		try{
			taskImpl.printValue();
			log.info("Task Completed");
			taskImpl.setLastRun(new Date());
			
		}catch(Exception e ){
			
			log.error("Exception Occured");
			e.printStackTrace();
			
		}
	}

}

Task Implementation class..

public class RouterTaskImpl implements RouterScheduler,LifecycleAware{
	
	static final String KEY = RouterTaskImpl.class.getName() + ":instance";
	private static final String JOB_NAME = RouterTaskImpl.class.getName() + ":job";

	
	private final PluginScheduler pluginScheduler;
	private long interval = 5000L;
	private Date lastrun = null;
	private final Logger log = Logger.getLogger(RouterTaskImpl.class);
	
	public RouterTaskImpl(PluginScheduler pluginScheduler) {
		this.pluginScheduler = pluginScheduler;
	}

	@Override
	public void onStart() {
		reschedule(interval);
		
	}
	
	@Override
	public void reschedule(long interval){
		this.interval = interval;
		Date start = setStartTime();
		pluginScheduler.scheduleJob(JOB_NAME, RouterTask.class, new HashMap<String,Object>(){{put(KEY,RouterTaskImpl.this);}}, start, interval);
		log.info("job Scheduled");
	}
	
	public void printValue(){
		log.info("Task running at (Newly Installed ).. " + new Date().toString() + "\n");
		System.out.println("Task running at " + new Date().toString() + "\n");
	}
	
	void setLastRun(Date date) {
       lastrun = date;
    }

	public Date setStartTime(){
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.HOUR_OF_DAY,16);
		cal.set(Calendar.MINUTE,20);
		cal.set(Calendar.SECOND,0);
		cal.set(Calendar.MILLISECOND,0);

		Date startDate = cal.getTime();
		return startDate;
		
	}
	
}
Monitor Class
public interface TicketRouterScheduler {

	public void reschedule(long interval);
}

Nothing seems to be wrong, yet the plug-in does not print anything as expected, not does it display a scheduled task under system-> Scehduler details.Any pointers on what I'm doing wrong here would be much appreciated.

Thanks.

5 answers

1 vote
Prameesha Samarakoon January 15, 2014

Hi Mizan,

It was a typo with the question, and was accurate in the code. The problem was with the atlassian-plugin.xml as you suggested but it was with the SAL version given in the file. Fixed the error and the task works fine.

Thanks a lot for your support and suggestions, it was really helpful.

0 votes
Prakhar Srivastav June 3, 2016

@Prameesha Samarakoon

Can you please let me know the fix of this problem?

I am stuck in the same.

Regards

Prakhar

0 votes
Mizan
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.
January 15, 2014

Hi Prameesha ,

You are right , this should get displayed under Scheduler Details but since it does not I believe there is some error in the atlassian-plugin.xml , you can check if you are reffering to correct classes and interfaces and there is no typo error .

Your monitor class is TicketRouterScheduler but in the xml i see it as RouterScheduler

0 votes
Prameesha Samarakoon January 15, 2014

Hi Mizan,

Thanks a lot for your response. I tried out your suggestion but nothing related to the plug-in gets printed.Although I uploaded the plug-in and it is displayed under installed plug-ins, the plug-in does not seem to be working or communicating with the JIRA scheduler. According to what I've done here shouldn't this task be displayed/scheduled under System->Scheduler Details? Is there something specifically wrong with what I'm doing?

Thanks

0 votes
Mizan
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.
January 15, 2014

try using log.error() instead of log.info() then check your logs OR check the logging level in JIRA logging refer https://confluence.atlassian.com/display/JIRA/Logging+and+Profiling<br< a="">>

Suggest an answer

Log in or Sign up to answer