Skip to content

Commit

Permalink
fix(schedules): determine trigger off current UTC time
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp committed Jun 26, 2023
1 parent ce0385e commit 6c7dac6
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions cmd/vela-server/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,16 @@ func processSchedules(compiler compiler.Engine, database database.Interface, met
continue
}

// create a variable to track if a build should be triggered based off the schedule
trigger := false
gron := gronx.New()

// parse the previous occurrence of the entry for the schedule
prevTime, err := gronx.PrevTick(schedule.GetEntry(), true)
// determine if a build should be triggered based off the schedule
trigger, err := gron.IsDue(schedule.GetEntry(), time.Now().UTC())
if err != nil {
logrus.WithError(err).Warnf("%s for %s", baseErr, schedule.GetName())

continue
}

// parse the next occurrence of the entry for the schedule
nextTime, err := gronx.NextTick(schedule.GetEntry(), true)
if err != nil {
logrus.WithError(err).Warnf("%s for %s", baseErr, schedule.GetName())

continue
}

// parse the UNIX timestamp from when the last build was triggered for the schedule
t := time.Unix(schedule.GetScheduledAt(), 0).UTC()

// check if the time since the last triggered build is greater than the entry duration for the schedule
if time.Since(t) > nextTime.Sub(prevTime) {
// trigger a build for the schedule since it has not previously ran
trigger = true
}

if trigger && schedule.GetActive() {
err = processSchedule(schedule, compiler, database, metadata, queue, scm)
if err != nil {
Expand Down

0 comments on commit 6c7dac6

Please sign in to comment.