From 19591aced9dcfeddda6573a2be8fb0826115f771 Mon Sep 17 00:00:00 2001 From: himeshr Date: Mon, 21 Aug 2023 09:36:19 +0530 Subject: [PATCH] #48 | Set the ETL ScheduledJobRun startTime based on trigger fireTime. --- .../org/avniproject/etl/domain/quartz/ScheduledJobRun.java | 5 +++-- .../java/org/avniproject/etl/scheduler/EtlJobListener.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/avniproject/etl/domain/quartz/ScheduledJobRun.java b/src/main/java/org/avniproject/etl/domain/quartz/ScheduledJobRun.java index d3fe24c..7251666 100644 --- a/src/main/java/org/avniproject/etl/domain/quartz/ScheduledJobRun.java +++ b/src/main/java/org/avniproject/etl/domain/quartz/ScheduledJobRun.java @@ -35,11 +35,12 @@ public class ScheduledJobRun { public static ScheduledJobRun create(JobDetail jobDetail, Trigger trigger) { ScheduledJobRun scheduledJobRun = new ScheduledJobRun(); scheduledJobRun.jobName = jobDetail.getKey().getName(); - scheduledJobRun.startedAt = trigger.getStartTime(); + scheduledJobRun.startedAt = trigger.getNextFireTime(); return scheduledJobRun; } - public void ended(JobExecutionException jobException) { + public void ended(JobExecutionException jobException, Trigger trigger) { + this.startedAt = trigger.getPreviousFireTime(); this.endedAt = new Date(); if (jobException != null) errorMessage = ExceptionUtil.getStackTraceAsString(getAppException(jobException)); diff --git a/src/main/java/org/avniproject/etl/scheduler/EtlJobListener.java b/src/main/java/org/avniproject/etl/scheduler/EtlJobListener.java index 0b68494..5772fc5 100644 --- a/src/main/java/org/avniproject/etl/scheduler/EtlJobListener.java +++ b/src/main/java/org/avniproject/etl/scheduler/EtlJobListener.java @@ -49,7 +49,7 @@ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jo log.error("Error in job run", jobException); } ScheduledJobRun scheduledJobRun = scheduledJobRunRepository.getLastRun(context.getJobDetail().getKey().getName()); - scheduledJobRun.ended(jobException); + scheduledJobRun.ended(jobException, context.getTrigger()); scheduledJobRun.setSuccess(jobException == null); scheduledJobRunRepository.save(scheduledJobRun); } catch (Exception exception) {