Page tree

이 문서는 Java에서 Jira Scheduler를 구현하는 방법을 공유하기 위해 작성되었다.


도구명jira, java
버전8.22




Scheduler register, unregister

onStart, onStop Override

@ExportAsService
@Named
public class ScheduleSync implements LifecycleAware {

 	@ComponentImport
    private final SchedulerService schedulerService;

	private final JobId ISSUE_SYNC_JOB_ID = JobId.of("issue-sync-job-id");
  
	@Override
    public void onStart() {
        issueSyncService.doLogin();
        JobConfig jobConfig = JobConfig.forJobRunnerKey(ScheduleJob.ISSUE_SYNC_JOBRUNNER_KEY)
                        .withSchedule(Schedule.forCronExpression((String) getDbInfo1().get("cron")))
                                .withRunMode(RunMode.RUN_LOCALLY);
        schedulerService.scheduleJob(ISSUE_SYNC_JOB_ID, jobConfig);
    }

    @Override
    public void onStop() {
        schedulerService.unscheduleJob(ISSUE_SYNC_JOB_ID);
    }

}
  •  LifecycleAware의 plugin onStart, onStop 메소드 구현
  • onStart : plugin이 시작될 때 scheduleService api - Jira scheduler register (do Job)
  • onStop : plugin이 종료되면 scheduleService api - Jira scheduler unregister (stop Job)


scheduleService 응용

public void controlJob() throws SchedulerServiceException {
        if(getDbInfo1().get("scheduleJob").equals("on")){
            doJob();
        }else if(getDbInfo1().get("scheduleJob").equals("off") || getDbInfo1().get("scheduleJob") == null){
            stopJob();
        }
    }
  • 서버 DB에 Scheduler정보를 저장, 임의적으로 register, unregister handling
  • plugin이 작동되는 동안 scheduler on/off 가능 (servlet - templateRenderer로 vm, js 형식으로 UI 기능 구현)


JobId, JobRunnerKey 등록

public class ScheduleJob implements JobRunner {
	public static final JobRunnerKey ISSUE_SYNC_JOBRUNNER_KEY = JobRunnerKey.of(ScheduleJob.class.getCanonicalName());
}

public class ScheduleSync implements LifecycleAware {
	private final JobId ISSUE_SYNC_JOB_ID = JobId.of("issue-sync-job-id");

 	JobConfig jobConfig = JobConfig.forJobRunnerKey(ScheduleJob.ISSUE_SYNC_JOBRUNNER_KEY)
                        .withSchedule(Schedule.forCronExpression((String) getDbInfo1().get("cron")))
                        .withRunMode(RunMode.RUN_LOCALLY);
        schedulerService.scheduleJob(ISSUE_SYNC_JOB_ID, jobConfig);
}
  •  ScheduleJob, ScheduleSync class에 각 저장한 JobRunnerKey, JobId를 파라미터로 Schedule Job Run



Jira Scheduler 동작 확인

Jira Scheduler menu

  • DB에 CRON 표현식과 Scheduler register 여부 저장



  • 시스템 - 스케쥴러 상세정보 - 설정한 scheduler key 검색
  • 추가한 Scheduler의 Key와 다음 실행될 일정에 대한 정보




참조



  • No labels