Skip to content

Commit

Permalink
Merge pull request #22 from lucidsoftware/indexChanges
Browse files Browse the repository at this point in the history
Index added to trigger history table, primary key changed
  • Loading branch information
disaacson committed May 14, 2015
2 parents 4815693 + 460f566 commit 9682c32
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion worker/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "piezo-worker"

organization := "com.lucidchart"

version := "1.8-SNAPSHOT"
version := "1.8"

scalaVersion := "2.10.1"

Expand Down
3 changes: 2 additions & 1 deletion worker/src/main/resources/create_history_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CREATE TABLE trigger_history(
actual_start DATETIME,
finish DATETIME NOT NULL,
misfire BOOLEAN NOT NULL,
PRIMARY KEY(trigger_group, trigger_name, scheduled_start),
fire_instance_id VARCHAR(120) NULL,
PRIMARY KEY(trigger_group, trigger_name, scheduled_start, fire_instance_id),
KEY sched_start_key(scheduled_start)
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ class TriggerHistoryModel(props: Properties) {
val logger = LoggerFactory.getLogger(this.getClass)
val connectionProvider = new ConnectionProvider(props)

def addTrigger(trigger:Trigger, actualStart:Option[Date], misfire:Boolean) {
def addTrigger(trigger: Trigger, actualStart: Option[Date], misfire: Boolean, fireInstanceId: Option[String]) {
val connection = connectionProvider.getConnection
try {
val prepared = connection.prepareStatement("""INSERT INTO trigger_history(trigger_name, trigger_group, scheduled_start, actual_start, finish, misfire) VALUES(?, ?, ?, ?, ?, ?)""")
val prepared = connection.prepareStatement("""INSERT INTO trigger_history(trigger_name, trigger_group, scheduled_start, actual_start, finish, misfire, fire_instance_id) VALUES(?, ?, ?, ?, ?, ?, ?)""")
prepared.setString(1, trigger.getKey.getName)
prepared.setString(2, trigger.getKey.getGroup)
prepared.setTimestamp(3, new Timestamp(Option(trigger.getPreviousFireTime).getOrElse(new Date(0)).getTime))
prepared.setTimestamp(4, actualStart.map(date => new Timestamp(date.getTime)).getOrElse(null))
prepared.setTimestamp(5, new Timestamp(System.currentTimeMillis))
prepared.setBoolean(6, misfire)
prepared.setString(7, fireInstanceId.getOrElse(null))
prepared.executeUpdate()
} catch {
case e:Exception => logger.error("error in recording end of trigger",e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WorkerTriggerListener(props: Properties) extends TriggerListener {

def triggerComplete(trigger: Trigger, context: JobExecutionContext, triggerInstructionCode: CompletedExecutionInstruction) {
try {
triggerHistoryModel.addTrigger(trigger, Some(context.getFireTime), misfire=false)
triggerHistoryModel.addTrigger(trigger, Some(context.getFireTime), misfire=false, Some(context.getFireInstanceId))
val statsKey = "triggers." + trigger.getKey.getGroup + "." + trigger.getKey.getName + ".completed"
StatsD.increment(statsKey)
} catch {
Expand All @@ -29,7 +29,7 @@ class WorkerTriggerListener(props: Properties) extends TriggerListener {

def triggerMisfired(trigger: Trigger) {
try {
triggerHistoryModel.addTrigger(trigger, None, misfire=true)
triggerHistoryModel.addTrigger(trigger, None, misfire=true, None)
val statsKey = "triggers." + trigger.getKey.getGroup + "." + trigger.getKey.getName + ".misfired"
StatsD.increment(statsKey)
} catch {
Expand Down

0 comments on commit 9682c32

Please sign in to comment.