Eh don't feel like writing scheduler rn

main
Jef Roosens 2022-04-14 21:20:10 +02:00
parent c8af362a4a
commit c8fc683384
Signed by untrusted user: Jef Roosens
GPG Key ID: B580B976584B5F30
3 changed files with 53 additions and 3 deletions

View File

@ -0,0 +1,45 @@
module daemon
import git
import time
import sync.stdatomic
// update_builds starts as many builds as possible.
fn (mut d Daemon) update_builds() ? {
now := time.now()
for d.queue.len() > 0 {
if d.queue.peek() ?.timestamp < now {
sb := d.queue.pop() ?
// If this build couldn't be scheduled, no more will be possible.
if !d.start_build(sb.repo_id)? {
break
}
} else {
break
}
}
}
// start_build starts a build for the given repo_id.
fn (mut d Daemon) start_build(repo_id string) ?bool {
for i in 0..d.atomics.len {
if stdatomic.load_u64(&d.atomics[i]) == 0 {
stdatomic.store_u64(&d.atomics[i], 1)
go d.run_build(i, d.repos_map[repo_id])
return true
}
}
return false
}
fn (mut d Daemon) run_build(build_index int, repo git.GitRepo) ? {
time.sleep(10 * time.second)
stdatomic.store_u64(&d.atomics[build_index], 2)
}

View File

@ -61,8 +61,13 @@ pub fn init_daemon(logger log.Log, address string, api_key string, base_image st
// run starts the actual daemon process. It runs builds when possible &
// periodically refreshes the list of repositories to ensure we stay in sync.
pub fn (mut d Daemon) run() ? {
println(d.queue)
println('i am running')
for {
d.update_builds() ?
println(d.queue)
println(d.atomics)
time.sleep(60 * time.second)
}
}
fn (mut d Daemon) renew_repos() ? {

View File

@ -9,5 +9,5 @@ default_arch = "x86_64"
address = "http://localhost:8000"
global_schedule = '0 3'
global_schedule = '* *'