Forums

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

How to trigger a timer every midnight to make rest call.

Bani March 2, 2018

Hi 

I am developing a Jira plugin and trying to set substitutes for team leaders for a particular time interval.  I am providing team permission to substitute and need to check every midnight if the substitutes time interval is over or not . if yes then need to remove permission for the substitute,

I have already developed the code for setting and removing substitute but now i m searching how to add a timer to jira so that it will make a rest call every midnight to check whether current date reside in  substitutes time interval if not then delete the permission.

 

Thnanks!!

4 answers

0 votes
Bani March 7, 2018

Hey ..

actually in my authentication helper i'm appending http req.

Is it possible to create a jsession id for  the user  using name and password or if we can create a cookie to make a tempo rest api call .... 

 

Thanks 

0 votes
Aleksandr Zuevich
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.
March 6, 2018

I don't know exactly how your AuthenticationHelper and TempoRestClient are implemented but maybe you need to do something like:

JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext();
authContext.setLoggedInUser(ComponentAccessor.getUserManager().getUserByKey("username"));
0 votes
Bani March 6, 2018

Is there some another way in which i can create a timer then  and append my http req too ?because i ll need admin rights to make a rest call to get tempo teams 

0 votes
Aleksandr Zuevich
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.
March 2, 2018
Bani March 5, 2018

HI Aleksander ,

Thanks for the link .

As I described earlier,I am trying to develop a  substitute functionality in JIRA in which team leaders can assign their substitutes and give them permission to approve the timesheet of his team members,

It will be valid for a specified interval for that interval i am giving tempo team permission to the substitute. After the time interval is over i want to remove the team permission for the substitute,

I already have the code to remove and set permission for substitute i need to create a timer which will run every mid night to check weather team's substitute reside in the time interval for team permission or not if not then remove it .

I tried to follow this link.

I  used following steps to create a timer.

1. I added the maven dependency.

2. Imported the SAL scheduler as defined in link.

3. Wrote a Task in which I implemented PluginJob and also pass the task  class name.I also injected the services here which I was using to delete the team permission here for substitute after checking the time interval.

// i m getting error  in this step at the point where i tried to call my authentication helper to set the httprequest which i will need to get all the tempo teams and to get the substitute for them . I am getting following error.

2:15:49,422 Caesium-1-1 ERROR ServiceRunner [c.a.scheduler.core.JobLauncher] Scheduled job with ID 'JiraPluginScheduler:com.foxconn.dta.schedular.RemoveOldSubstituteTeamPermissionsimpl:job' failed
[INFO] [talledLocalContainer] java.lang.NullPointerException
[INFO] [talledLocalContainer] at com.foxconn.dta.schedular.RemoveOldSubstitute.execute(RemoveOldSubstitute.java:31)
[INFO] [talledLocalContainer] at com.atlassian.sal.jira.scheduling.JiraPluginScheduler$JobDescriptor.runJob(JiraPluginScheduler.java:110)
[INFO] [talledLocalContainer] at com.atlassian.sal.jira.scheduling.JiraPluginScheduler.runJob(JiraPluginScheduler.java:80)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.core.JobLauncher.runJob(JobLauncher.java:153)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.core.JobLauncher.launchAndBuildResponse(JobLauncher.java:118)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.core.JobLauncher.launch(JobLauncher.java:97)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.launchJob(CaesiumSchedulerService.java:443)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeLocalJob(CaesiumSchedulerService.java:410)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeQueuedJob(CaesiumSchedulerService.java:388)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService$1.consume(CaesiumSchedulerService.java:285)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService$1.consume(CaesiumSchedulerService.java:282)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeJob(SchedulerQueueWorker.java:65)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeNextJob(SchedulerQueueWorker.java:59)
[INFO] [talledLocalContainer] at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.run(SchedulerQueueWorker.java:34)
[INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:748)

 

Thanks !!

Aleksandr Zuevich
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.
March 5, 2018

Could you show your RemoveOldSubstitute.java?

Bani March 5, 2018

public class RemoveOldSubstitute implements PluginJob {
@Inject
private SubstituteSettingsService substituteSettingService;
@Inject
private TempoRestClient tempoRestClient;
@Context
HttpServletRequest httpRequest;
@Inject
AuthenticationHelper authenticationHelper;
@Override
public void execute(Map<String, Object> jobDataMap) {
final RemoveOldSubstituteTeamPermissionsimpl monitor = (RemoveOldSubstituteTeamPermissionsimpl) jobDataMap
.get(RemoveOldSubstituteTeamPermissionsimpl.KEY);
assert monitor != null;

 

//here i m getting the error .. httprequest is null here how i can add request here .
authenticationHelper.setHttpRequest(httpRequest);

 

//getting all the teams info here 
List<TempoTeam> teams = tempoRestClient.getTeamListForUser();

if (teams != null && !teams.isEmpty()) {
for (TempoTeam team : teams) {
substituteSettingService.deleteTeamLeadSubstitute(team.getId(), team.getLead());

}
}

}

}

Aleksandr Zuevich
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.
March 6, 2018

There is no httpRequest here because you run your method in scheduled mode, without user interaction. You have to think how to authenticate another way.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events