@@ -21,12 +21,14 @@ type Update struct {
2121 // Last whether or not this is the last update, and no more will be coming.
2222 // If true, perform this action and then end.
2323 Last bool
24+ // Next time until the next update, if applicable.
25+ Next time.Duration
2426}
2527
26- func sendTimer (c chan Update , last bool ) {
28+ func sendTimer (c chan Update , last bool , next time. Duration ) {
2729 // make the channel write non-blocking
2830 select {
29- case c <- Update {Last : last }:
31+ case c <- Update {Last : last , Next : next }:
3032 default :
3133 }
3234}
@@ -66,17 +68,14 @@ func Timer(opts TimerOptions) (<-chan Update, error) {
6668
6769 // if once, ignore all delays and go
6870 if opts .Once {
69- sendTimer (c , true )
71+ sendTimer (c , true , 0 )
7072 return
7173 }
7274
7375 // create our delay and timer loop and go
7476 for {
7577 lastRun := time .Now ().UTC ()
7678
77- // not once - run the first backup
78- sendTimer (c , false )
79-
8079 if opts .Cron != "" {
8180 now := time .Now ().UTC ()
8281 delay , _ = waitForCron (opts .Cron , now )
@@ -95,6 +94,9 @@ func Timer(opts TimerOptions) (<-chan Update, error) {
9594 delay = time .Duration (opts .Frequency - passed ) * time .Minute
9695 }
9796
97+ // not once - run the first backup
98+ sendTimer (c , false , delay )
99+
98100 // if delayMins is 0, this will do nothing, so it does not hurt
99101 time .Sleep (delay )
100102 }
@@ -178,6 +180,7 @@ func (e *Executor) Timer(timerOpts TimerOptions, cmd func() error) error {
178180 if update .Last {
179181 break
180182 }
183+ e .Logger .Infof ("next run in %s" , update .Next .String ())
181184 }
182185 return nil
183186}
0 commit comments