Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When expiring lock, set lastRunTime to startTime of last successful jobRun (or null) #633

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ class ScheduledJobRunner implements Runnable {
if (lastRunDt.isBefore(lockCheckTime)) {
// recover failed job without lock reset, run it if schedule says to
logger.warn("Lock expired: found lock for job ${jobName} from ${lastRunDt}, more than ${expireLockTime} minutes old, ignoring lock")
serviceJobRunLock.set("jobRunId", null).update()
// treat expired lock as a failed jobRun and set lastRunTime to last successful run
EntityValue lastSuccessfulJobRun = efi.find("moqui.service.job.ServiceJobRun").condition("jobName", jobName)
.condition("hasError", "N").orderBy("-startTime").limit(1).useCache(false).list().getFirst()
lastRunTime = (Timestamp) lastSuccessfulJobRun?.startTime
lastRunDt = (lastRunTime != (Timestamp) null) ?
ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastRunTime.getTime()), now.getZone()) : null
serviceJobRunLock.set("jobRunId", null).set("lastRunTime", lastRunTime).update()
} else {
// normal lock, skip this job
logger.info("Lock found for job ${jobName} from ${lastRunDt} run ID ${serviceJobRunLock.jobRunId}, not running")
Expand Down
Loading