From 65d6aae701d087f381ff5f11ec90f7afda5e9f2c Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 12 Apr 2022 11:10:49 +0200 Subject: [PATCH] Made sure unix value is calculated --- src/cron/cron.v | 44 +++++++++++-------------------------------- src/cron/expression.v | 4 ++-- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/src/cron/cron.v b/src/cron/cron.v index a049eec8..cd32c448 100644 --- a/src/cron/cron.v +++ b/src/cron/cron.v @@ -3,6 +3,7 @@ module cron import git import datatypes import time +import rand struct ScheduledBuild { repo git.GitRepo @@ -14,42 +15,19 @@ fn (r1 ScheduledBuild) < (r2 ScheduledBuild) bool { } pub fn cron(conf Config) ? { - // mut queue := datatypes.MinHeap{} - // repos_map := git.get_repos(conf.address, conf.api_key) ? + mut queue := datatypes.MinHeap{} - // for _, repo in repos_map { - // scheduled := ScheduledBuild{ - // repo: repo - // timestamp: 25 - // } + for _ in 0..5000 { + minute := rand.int_in_range(0, 60) ? + hour := rand.int_in_range(0, 23) ? + ce := parse_expression('$minute $hour') ? - // queue.insert(scheduled) - // } - - // println(queue) - // exp := '10/2 5 *' - // println(parse_expression(exp) ?) - ce := parse_expression('0 35 */2') ? - println(ce) - // ce := CronExpression{ - // minutes: [0] - // hours: [3] - // days: [1, 2, 3, 4, 5, 6] - // months: [1, 2] - // } - mut t := time.Time{ - year: 2022 - month: 12 - minute: 9 - hour: 13 - day: 12 + t := ce.next_from_now() ? + // println(t) + queue.insert(t) } - // mut t := time.now() - println(t) - - for _ in 1 .. 25 { - t = ce.next(t) ? - println(t) + for queue.len() > 0 { + println(queue.pop() ?) } } diff --git a/src/cron/expression.v b/src/cron/expression.v index 0bc15912..d275a423 100644 --- a/src/cron/expression.v +++ b/src/cron/expression.v @@ -101,13 +101,13 @@ pub fn (ce &CronExpression) next(ref time.Time) ?time.Time { year++ } - return time.Time{ + return time.new_time(time.Time{ year: year month: month day: day minute: minute hour: hour - } + }) } fn (ce &CronExpression) next_from_now() ?time.Time {