Skip to content

Commit

Permalink
fix(cron): Adding fuzzy expression parsing support (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert committed Aug 9, 2018
1 parent 1b15a73 commit 3d2a707
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.spinnaker.echo.scheduler.actions.pipeline.impl

import com.google.common.collect.Lists
import com.netflix.scheduledactions.triggers.CronExpressionFuzzer
import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.echo.model.Pipeline
import com.netflix.spinnaker.echo.model.Trigger
Expand Down Expand Up @@ -199,14 +200,14 @@ class MissedPipelineTriggerCompensationJob implements ApplicationListener<Contex
}

try {
CronExpression expr = new CronExpression(trigger.cronExpression)
CronExpression expr = getCronExpression(trigger)
expr.timeZone = dateContext.timeZone

if (missedExecution(expr, lastExecution, dateContext.triggerWindowFloor, dateContext.now, pipeline)) {
pipelineInitiator.call(pipeline)
}
} catch (ParseException e) {
log.error("Error parsing cron expression (${trigger.cronExpression}) for pipeline ${pipeline.id}")
log.error("Error parsing cron expression (${trigger.cronExpression}) for pipeline ${pipeline.id}", e)
registry.counter("orca.errors", "exception", error.getClass().getName()).increment()
}
}
Expand All @@ -224,6 +225,13 @@ class MissedPipelineTriggerCompensationJob implements ApplicationListener<Contex
.findAll { Trigger it -> it && it.enabled && it.type == CRON.toString() }
}

private static CronExpression getCronExpression(Trigger trigger) {
if (CronExpressionFuzzer.hasFuzzyExpression(trigger.cronExpression)) {
return new CronExpression(CronExpressionFuzzer.fuzz(trigger.id, trigger.cronExpression))
}
return new CronExpression(trigger.cronExpression)
}

private static Date getLastValidTimeInWindow(CronExpression expr, Date from, Date to) {
Date valid = expr.getNextValidTimeAfter(from)
if (valid.after(to)) {
Expand Down

0 comments on commit 3d2a707

Please sign in to comment.