How to create a scheduled task?

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?

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you