Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a scheduled task?

Jerome Bleichenbacher
Contributor
August 3, 2017

Hi there!

 

I want to write a Plugin for Jira and I'm relatively new to Java. This Plugin should grab some data from an external system and persist it in the active-object-db. Its for internal purposes only, so we want to develop it with the latest Jira-Version and latest technologies respectively.

 

But I have no clue how to use the scheduler-api and therefore I've searched the web. All I found was a bunch of old stuff using quertz or the sal-scheduler and afaik there both deprecated. However, I've also found the Awesome-Plugin-Example at bitbucket from Chris Fuller. Unfortunately it is way to complex for me just to figure out how to use the scheduler. Moreover it does not even compile with atlas-mvn package when I download the source.

 

I'm familiar with the atlas-sdk and I've already created a plugin-skeleton. Can somebody guiding me through the rest?

 

Firstly I need a Class which registers the scheduler - what files do I need and how do they look like? I started with two files:

PluginEnabledHandler.java.

package ch.kms.jira.svnint;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.plugin.event.events.PluginDisabledEvent;
import com.atlassian.plugin.event.events.PluginEnabledEvent;


import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;


public interface PluginEnabledHandler {

void afterPropertiesSet() throws Exception;

void destroy() throws Exception ;

void onPluginEnabled(PluginEnabledEvent event) throws Exception ;
}

 & PluginEnabledHandlerImpl.java.

package ch.kms.jira.svnint;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//import org.springframework.beans.factory.DisposableBean;
//import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.*;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.*;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Component.*;
import org.springframework.stereotype.*;

import com.atlassian.plugin.spring.scanner.*;
import com.atlassian.plugin.spring.scanner.annotation.*;
import com.atlassian.plugin.spring.scanner.annotation.export.*;
import com.atlassian.plugin.spring.scanner.annotation.imports.*;
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;


import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;


import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.plugin.event.events.PluginDisabledEvent;
import com.atlassian.plugin.event.events.PluginEnabledEvent;


@ExportAsService({PluginEnabledHandler.class})
@Named("pluginEnabledHandler")
@Scanned
//public class PluginEnabledHandlerImpl implements InitializingBean, DisposableBean, PluginEnabledHandler {

public class PluginEnabledHandlerImpl implements InitializingBean, DisposableBean {

@ComponentImport
private final EventPublisher eventPublisher;

@Inject
public PluginEnabledHandlerImpl(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}

public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
}

public void destroy() throws Exception {
eventPublisher.unregister(this);
}

@EventListener
public void onPluginEnabled(PluginEnabledEvent event) throws Exception {
Plugin plugin = event.getPlugin();

//LOG.warn("****************************************************** Enabled");


if ("myplugin.key".equals(plugin.getKey())) {
// configure on enable
}
}
}

I tried a lot of different impors with no luck. atlas-mvn package always says: 

cannot find symbol

symbol: class Named

What am I doing wrong?

1 answer

0 votes
bzorg47
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 27, 2018

Hi,

I know this is an old question but I was also trying to find a newer code then what is in the Atlassian documentation. 

In the end I have experimented and made an example plugin that works.

https://bitbucket.org/bzorg47/scheduler

Maybe it will help somebody else who is looking for a more current example.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events