forked from vieter-v/vieter
WIP server queeu stuff
parent
6281ef7607
commit
f7ca005ad5
|
|
@ -20,6 +20,6 @@ pub fn agent(conf Config) ! {
|
||||||
logger.set_full_logpath(log_file)
|
logger.set_full_logpath(log_file)
|
||||||
logger.log_to_console_too()
|
logger.log_to_console_too()
|
||||||
|
|
||||||
mut d := agent.agent_init(logger, conf)
|
mut d := agent_init(logger, conf)
|
||||||
d.run()
|
d.run()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ pub:
|
||||||
max_concurrent_builds int = 1
|
max_concurrent_builds int = 1
|
||||||
polling_frequency int = 30
|
polling_frequency int = 30
|
||||||
// Architecture of agent
|
// Architecture of agent
|
||||||
/* arch string */
|
// arch string
|
||||||
/* image_rebuild_frequency int = 1440 */
|
// image_rebuild_frequency int = 1440
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd returns the cli module that handles the cron daemon.
|
// cmd returns the cli module that handles the cron daemon.
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,7 @@ pub fn (mut d AgentDaemon) run() {
|
||||||
free_builds := d.update_atomics()
|
free_builds := d.update_atomics()
|
||||||
|
|
||||||
if free_builds > 0 {
|
if free_builds > 0 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ fn main() {
|
||||||
schedule.cmd(),
|
schedule.cmd(),
|
||||||
man.cmd(),
|
man.cmd(),
|
||||||
aur.cmd(),
|
aur.cmd(),
|
||||||
agent.cmd()
|
agent.cmd(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
app.setup()
|
app.setup()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
module server
|
||||||
|
|
||||||
|
import web
|
||||||
|
import web.response { new_response }
|
||||||
|
// import db
|
||||||
|
import time
|
||||||
|
// import os
|
||||||
|
// import util
|
||||||
|
// import models { BuildLog, BuildLogFilter }
|
||||||
|
|
||||||
|
['/api/v1/builds/poll'; auth; get]
|
||||||
|
fn (mut app App) v1_poll_build_queue() web.Result {
|
||||||
|
arch := app.query['arch'] or {
|
||||||
|
return app.json(.bad_request, new_response('Missing arch query arg.'))
|
||||||
|
}
|
||||||
|
|
||||||
|
max_str := app.query['max'] or {
|
||||||
|
return app.json(.bad_request, new_response('Missing max query arg.'))
|
||||||
|
}
|
||||||
|
max := max_str.int()
|
||||||
|
|
||||||
|
|
||||||
|
mut out := []
|
||||||
|
|
||||||
|
now := time.now()
|
||||||
|
lock app.build_queue {
|
||||||
|
for app.build_queue.len() > 0 && out.len() < max {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,9 @@ import log
|
||||||
import repo
|
import repo
|
||||||
import util
|
import util
|
||||||
import db
|
import db
|
||||||
|
import datatypes { MinHeap }
|
||||||
|
import build { BuildConfig }
|
||||||
|
import time
|
||||||
|
|
||||||
const (
|
const (
|
||||||
log_file_name = 'vieter.log'
|
log_file_name = 'vieter.log'
|
||||||
|
|
@ -14,12 +17,25 @@ const (
|
||||||
logs_dir_name = 'logs'
|
logs_dir_name = 'logs'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
struct ScheduledBuild {
|
||||||
|
pub:
|
||||||
|
timestamp time.Time
|
||||||
|
target_id int
|
||||||
|
build_config BuildConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloaded operator for comparing ScheduledBuild objects
|
||||||
|
fn (r1 ScheduledBuild) < (r2 ScheduledBuild) bool {
|
||||||
|
return r1.timestamp < r2.timestamp
|
||||||
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
web.Context
|
web.Context
|
||||||
pub:
|
pub:
|
||||||
conf Config [required; web_global]
|
conf Config [required; web_global]
|
||||||
pub mut:
|
pub mut:
|
||||||
repo repo.RepoGroupManager [required; web_global]
|
repo repo.RepoGroupManager [required; web_global]
|
||||||
|
build_queue shared MinHeap<ScheduledBuild>
|
||||||
db db.VieterDb
|
db db.VieterDb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,5 +93,6 @@ pub fn server(conf Config) ! {
|
||||||
conf: conf
|
conf: conf
|
||||||
repo: repo
|
repo: repo
|
||||||
db: db
|
db: db
|
||||||
|
build_queue: MinHeap<ScheduledBuild>{}
|
||||||
}, conf.port)
|
}, conf.port)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue