summaryrefslogtreecommitdiffstats
path: root/modules/cron/constantdelay.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-06-13 13:01:52 -0400
committerUnknown <joe2010xtmf@163.com>2014-06-13 13:01:52 -0400
commitd952b4200c7c024ff5a809a3885bc79be9e4cce9 (patch)
treeb106d81f51a10144749e20c923713fd2c78643e4 /modules/cron/constantdelay.go
parente07674bff19dcc321a1611a3598d69c418ac8642 (diff)
downloadgitea-d952b4200c7c024ff5a809a3885bc79be9e4cce9.tar.gz
gitea-d952b4200c7c024ff5a809a3885bc79be9e4cce9.zip
Add corn rask monitor panel
Diffstat (limited to 'modules/cron/constantdelay.go')
-rw-r--r--modules/cron/constantdelay.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/cron/constantdelay.go b/modules/cron/constantdelay.go
new file mode 100644
index 0000000000..cd6e7b1be9
--- /dev/null
+++ b/modules/cron/constantdelay.go
@@ -0,0 +1,27 @@
+package cron
+
+import "time"
+
+// ConstantDelaySchedule represents a simple recurring duty cycle, e.g. "Every 5 minutes".
+// It does not support jobs more frequent than once a second.
+type ConstantDelaySchedule struct {
+ Delay time.Duration
+}
+
+// Every returns a crontab Schedule that activates once every duration.
+// Delays of less than a second are not supported (will round up to 1 second).
+// Any fields less than a Second are truncated.
+func Every(duration time.Duration) ConstantDelaySchedule {
+ if duration < time.Second {
+ duration = time.Second
+ }
+ return ConstantDelaySchedule{
+ Delay: duration - time.Duration(duration.Nanoseconds())%time.Second,
+ }
+}
+
+// Next returns the next time this should be run.
+// This rounds so that the next activation time will be on the second.
+func (schedule ConstantDelaySchedule) Next(t time.Time) time.Time {
+ return t.Add(schedule.Delay - time.Duration(t.Nanosecond())*time.Nanosecond)
+}