2022-04-09 09:46:07 +02:00
|
|
|
module cron
|
|
|
|
|
|
|
|
import git
|
2022-04-10 16:17:50 +02:00
|
|
|
import datatypes
|
|
|
|
import time
|
|
|
|
|
|
|
|
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-10 16:17:50 +02:00
|
|
|
// mut queue := datatypes.MinHeap<ScheduledBuild>{}
|
|
|
|
// repos_map := git.get_repos(conf.address, conf.api_key) ?
|
|
|
|
|
|
|
|
// for _, repo in repos_map {
|
|
|
|
// scheduled := ScheduledBuild{
|
|
|
|
// repo: repo
|
|
|
|
// timestamp: 25
|
|
|
|
// }
|
|
|
|
|
|
|
|
// queue.insert(scheduled)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// println(queue)
|
2022-04-11 22:16:31 +02:00
|
|
|
// exp := '10/2 5 *'
|
|
|
|
// println(parse_expression(exp) ?)
|
2022-04-12 10:35:29 +02:00
|
|
|
ce := parse_expression('0 35 */2') ?
|
2022-04-11 22:16:31 +02:00
|
|
|
println(ce)
|
|
|
|
// ce := CronExpression{
|
|
|
|
// minutes: [0]
|
|
|
|
// hours: [3]
|
|
|
|
// days: [1, 2, 3, 4, 5, 6]
|
|
|
|
// months: [1, 2]
|
|
|
|
// }
|
|
|
|
mut t := time.Time{
|
|
|
|
year: 2022
|
2022-04-11 22:30:22 +02:00
|
|
|
month: 12
|
2022-04-11 22:16:31 +02:00
|
|
|
minute: 9
|
|
|
|
hour: 13
|
|
|
|
day: 12
|
|
|
|
}
|
|
|
|
|
|
|
|
// mut t := time.now()
|
|
|
|
println(t)
|
|
|
|
|
2022-04-11 22:52:06 +02:00
|
|
|
for _ in 1 .. 25 {
|
2022-04-11 22:16:31 +02:00
|
|
|
t = ce.next(t) ?
|
|
|
|
println(t)
|
|
|
|
}
|
2022-04-09 09:46:07 +02:00
|
|
|
}
|