Skip to content

Commit

Permalink
#67 | Modify Avni scheduled jobs configuration for repeatInterval and…
Browse files Browse the repository at this point in the history
… misfireThreshold
  • Loading branch information
himeshr committed Aug 22, 2023
1 parent 604b204 commit fa1de68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.quartz.JobDataMap;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.impl.JobDetailImpl;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -85,6 +86,28 @@ public ResponseEntity createJob(@RequestBody JobScheduleRequest jobScheduleReque
if (latestJobRun != null)
return ResponseEntity.badRequest().body("Job already present");

JobDetailImpl jobDetail = getJobDetail(jobScheduleRequest, organisationIdentity, organisationIdentitiesInGroup);
scheduler.addJob(jobDetail, false);
Trigger trigger = getTrigger(jobScheduleRequest, jobDetail);
scheduler.scheduleJob(trigger);
logger.info(String.format("Job Scheduled for %s:%s", jobScheduleRequest.getJobEntityType(), jobScheduleRequest.getEntityUUID()));
return ResponseEntity.ok().body("Job Scheduled!");
}

private Trigger getTrigger(JobScheduleRequest jobScheduleRequest, JobDetailImpl jobDetail) {
SimpleScheduleBuilder scheduleBuilder = simpleSchedule()
.withIntervalInMinutes(scheduledJobConfig.getRepeatIntervalInMinutes()).repeatForever();

Trigger trigger = newTrigger()
.withIdentity(scheduledJobConfig.getTriggerKey(jobScheduleRequest.getEntityUUID()))
.forJob(jobDetail)
.withSchedule(scheduleBuilder)
.startAt(DateTimeUtil.nowPlusSeconds(5))
.build();
return trigger;
}

private JobDetailImpl getJobDetail(JobScheduleRequest jobScheduleRequest, OrganisationIdentity organisationIdentity, List<OrganisationIdentity> organisationIdentitiesInGroup) {
JobDetailImpl jobDetail = new JobDetailImpl();
jobDetail.setJobClass(EtlJob.class);
jobDetail.setDurability(true);
Expand All @@ -95,18 +118,7 @@ public ResponseEntity createJob(@RequestBody JobScheduleRequest jobScheduleReque
jobDetail.setName(jobScheduleRequest.getEntityUUID());
JobDataMap jobDataMap = scheduledJobConfig.createJobData(jobScheduleRequest.getJobEntityType());
jobDetail.setJobDataMap(jobDataMap);
scheduler.addJob(jobDetail, false);

Trigger trigger = newTrigger()
.withIdentity(scheduledJobConfig.getTriggerKey(jobScheduleRequest.getEntityUUID()))
.forJob(jobDetail)
.withSchedule(simpleSchedule().withIntervalInMinutes(scheduledJobConfig.getRepeatIntervalInMinutes()).repeatForever())
.startAt(DateTimeUtil.nowPlusSeconds(5))
.build();

scheduler.scheduleJob(trigger);
logger.info(String.format("Job Scheduled for %s:%s", jobScheduleRequest.getJobEntityType(), jobScheduleRequest.getEntityUUID()));
return ResponseEntity.ok().body("Job Scheduled!");
return jobDetail;
}

@PreAuthorize("hasAnyAuthority('admin')")
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/main-application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ spring.quartz.scheduler-name=${app.name}
spring.quartz.job-store-type=jdbc
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
spring.quartz.properties.org.quartz.threadPool.threadCount=${ETL_JOB_THREAD_COUNT:1}
spring.quartz.properties.org.quartz.jobStore.misfireThreshold = ${AVNI_SCHEDULED_JOB_TRIGGER_MISFIRE_THRESHOLD_IN_MILLISECONDS:3600000}

# Internal Scheduler config
avni.scheduledJob.repeatIntervalInMinutes=${AVNI_SCHEDULED_JOB_REPEAT_INTERVAL_IN_MINUTES:90}

#S3 Parameters
avni.bucket.name=${OPENCHS_BUCKET_NAME:dummy}
Expand Down Expand Up @@ -43,8 +47,6 @@ avni.keycloak.realms=%s/realms/%s
avni.keycloak.realm=On-premise

avni.idp.type=${AVNI_IDP_TYPE:none}
avni.scheduledJob.repeatIntervalInMinutes=${AVNI_SCHEDULED_JOB_REPEAT_INTERVAL_IN_MINUTES:60}

avni.security.allowedOrigins=${AVNI_SECURITY_ALLOWED_ORIGINS:http://localhost:6010}

spring.security.user.name=admin
Expand Down

0 comments on commit fa1de68

Please sign in to comment.