2022-04-09 09:46:07 +02:00
|
|
|
module cron
|
|
|
|
|
|
|
|
import git
|
2022-04-10 16:17:50 +02:00
|
|
|
import datatypes
|
|
|
|
import time
|
2022-04-12 11:10:49 +02:00
|
|
|
import rand
|
2022-04-10 16:17:50 +02:00
|
|
|
|
|
|
|
struct ScheduledBuild {
|
2022-04-10 16:48:37 +02:00
|
|
|
repo git.GitRepo
|
2022-04-10 16:17:50 +02:00
|
|
|
timestamp time.Time
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (r1 ScheduledBuild) < (r2 ScheduledBuild) bool {
|
|
|
|
return r1.timestamp < r2.timestamp
|
|
|
|
}
|
2022-04-09 09:46:07 +02:00
|
|
|
|
|
|
|
pub fn cron(conf Config) ? {
|
2022-04-12 11:10:49 +02:00
|
|
|
mut queue := datatypes.MinHeap<time.Time>{}
|
2022-04-10 16:17:50 +02:00
|
|
|
|
2022-04-12 11:10:49 +02:00
|
|
|
for _ in 0..5000 {
|
|
|
|
minute := rand.int_in_range(0, 60) ?
|
|
|
|
hour := rand.int_in_range(0, 23) ?
|
|
|
|
ce := parse_expression('$minute $hour') ?
|
2022-04-10 16:17:50 +02:00
|
|
|
|
2022-04-12 11:10:49 +02:00
|
|
|
t := ce.next_from_now() ?
|
|
|
|
// println(t)
|
|
|
|
queue.insert(t)
|
2022-04-11 22:16:31 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 11:10:49 +02:00
|
|
|
for queue.len() > 0 {
|
|
|
|
println(queue.pop() ?)
|
2022-04-11 22:16:31 +02:00
|
|
|
}
|
2022-04-09 09:46:07 +02:00
|
|
|
}
|