Skip to content

Commit

Permalink
Veto job execution if current trigger state is paused
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Reese committed Apr 30, 2022
1 parent fc8df6b commit b5fad6b
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.lucidchart.piezo

import com.timgroup.statsd.StatsDClient

import java.util.Properties
import org.quartz.Trigger.CompletedExecutionInstruction
import org.quartz.Trigger.{CompletedExecutionInstruction, TriggerState}
import org.quartz._
import org.slf4j.LoggerFactory

Expand All @@ -15,7 +16,20 @@ class WorkerTriggerListener(props: Properties, statsd: StatsDClient, useDatadog:

def getName: String = "WorkerTriggerListener"

def vetoJobExecution(trigger: Trigger, context: JobExecutionContext): Boolean = false
def vetoJobExecution(trigger: Trigger, context: JobExecutionContext): Boolean = {
// Called right before the job is about to execute on the worker.

/*
Under certain conditions, a job may come up for execution after a trigger
has been paused, leading to unexpected additional executions.
To fix this, right before Quartz starts the job, we check the _current_ trigger
state to ensure that job wasn't paused after the execution was queued.
*/

// Veto if current trigger state is paused
context.getScheduler.getTriggerState(trigger.getKey) == TriggerState.PAUSED
}

def triggerFired(trigger: Trigger, context: JobExecutionContext): Unit = {
val triggerKey = s"${trigger.getKey.getGroup}.${trigger.getKey.getName}"
Expand Down

0 comments on commit b5fad6b

Please sign in to comment.