Skip to content

Commit

Permalink
chore: save work
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp committed Jun 26, 2023
1 parent 6c7dac6 commit ef3010c
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cmd/vela-server/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ func processSchedules(compiler compiler.Engine, database database.Interface, met

// iterate through the list of active schedules
for _, s := range schedules {
gron := gronx.New()

// determine if a build should be triggered based off the schedule
due, err := gron.IsDue(s.GetEntry(), time.Now().UTC())
if err != nil {
logrus.WithError(err).Warnf("%s for %s", baseErr, s.GetName())

continue
}

// check if the schedule is due to trigger a build
if !due {
logrus.Tracef("waiting to schedule build for %s", s.GetName())

continue
}

// send API call to capture the schedule
//
// This is needed to ensure we are not dealing with a stale schedule since we fetch
Expand All @@ -49,17 +66,27 @@ func processSchedules(compiler compiler.Engine, database database.Interface, met
continue
}

gron := gronx.New()
// parse the previous occurrence of the entry for the schedule
prevTime, err := gronx.PrevTick(schedule.GetEntry(), true)
if err != nil {
logrus.WithError(err).Warnf("%s for %s", baseErr, schedule.GetName())

// determine if a build should be triggered based off the schedule
trigger, err := gron.IsDue(schedule.GetEntry(), time.Now().UTC())
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
}

if trigger && schedule.GetActive() {
// 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) && schedule.GetActive() {
err = processSchedule(schedule, compiler, database, metadata, queue, scm)
if err != nil {
logrus.WithError(err).Warnf("%s for %s", baseErr, schedule.GetName())
Expand Down

0 comments on commit ef3010c

Please sign in to comment.