forked from vieter-v/vieter
more wip
parent
f7ca005ad5
commit
722acb8ab3
|
|
@ -19,6 +19,7 @@ const (
|
|||
pub struct BuildConfig {
|
||||
pub:
|
||||
id int
|
||||
target_id int
|
||||
kind string
|
||||
url string
|
||||
branch string
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
module server
|
||||
|
||||
import web
|
||||
import web.response { new_response }
|
||||
// import db
|
||||
import web.response { new_data_response, new_response }
|
||||
import time
|
||||
import build { BuildConfig }
|
||||
// import os
|
||||
// import util
|
||||
// import models { BuildLog, BuildLogFilter }
|
||||
|
|
@ -19,13 +19,21 @@ fn (mut app App) v1_poll_build_queue() web.Result {
|
|||
}
|
||||
max := max_str.int()
|
||||
|
||||
|
||||
mut out := []
|
||||
mut out := []BuildConfig{}
|
||||
|
||||
now := time.now()
|
||||
lock app.build_queue {
|
||||
for app.build_queue.len() > 0 && out.len() < max {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
lock app.build_queues {
|
||||
mut queue := app.build_queues[arch] or { return app.json(.ok, new_data_response(out)) }
|
||||
|
||||
for queue.len() > 0 && out.len < max {
|
||||
next := queue.peek() or { return app.status(.internal_server_error) }
|
||||
|
||||
if next.timestamp < now {
|
||||
out << queue.pop() or { return app.status(.internal_server_error) }.config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return app.json(.ok, new_data_response(out))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ pub:
|
|||
data_dir string
|
||||
api_key string
|
||||
default_arch string
|
||||
global_schedule string = '0 3'
|
||||
port int = 8000
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import db
|
|||
import datatypes { MinHeap }
|
||||
import build { BuildConfig }
|
||||
import time
|
||||
import cron.expression
|
||||
|
||||
const (
|
||||
log_file_name = 'vieter.log'
|
||||
|
|
@ -19,9 +20,8 @@ const (
|
|||
|
||||
struct ScheduledBuild {
|
||||
pub:
|
||||
timestamp time.Time
|
||||
target_id int
|
||||
build_config BuildConfig
|
||||
timestamp time.Time
|
||||
config BuildConfig
|
||||
}
|
||||
|
||||
// Overloaded operator for comparing ScheduledBuild objects
|
||||
|
|
@ -34,9 +34,40 @@ struct App {
|
|||
pub:
|
||||
conf Config [required; web_global]
|
||||
pub mut:
|
||||
repo repo.RepoGroupManager [required; web_global]
|
||||
build_queue shared MinHeap<ScheduledBuild>
|
||||
db db.VieterDb
|
||||
repo repo.RepoGroupManager [required; web_global]
|
||||
// Keys are the various architectures for packages
|
||||
build_queues shared map[string]MinHeap<ScheduledBuild>
|
||||
db db.VieterDb
|
||||
}
|
||||
|
||||
fn (mut app App) init_build_queues() {
|
||||
// Initialize build queues
|
||||
mut i := 0
|
||||
mut targets := app.db.get_targets(limit: 25)
|
||||
|
||||
default_ce := expression.parse_expression(conf.global_schedule) or {
|
||||
return
|
||||
}
|
||||
|
||||
for targets.len > 0 {
|
||||
for t in targets {
|
||||
ce := parse_expression(t.schedule) or { default_ce }
|
||||
|
||||
for arch in t.arch {
|
||||
if arch !in app.build_queues {
|
||||
app.build_queues[arch] = Minheap<ScheduledBuild>{}
|
||||
}
|
||||
|
||||
build_config := BuildConfig{
|
||||
|
||||
}
|
||||
app.build_queues[arch].push(ScheduledBuild{
|
||||
timestamp: ce.next()
|
||||
config: build_config
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// server starts the web server & starts listening for requests
|
||||
|
|
@ -93,6 +124,6 @@ pub fn server(conf Config) ! {
|
|||
conf: conf
|
||||
repo: repo
|
||||
db: db
|
||||
build_queue: MinHeap<ScheduledBuild>{}
|
||||
build_queues: map[string]MinHeap<ScheduledBuild>{}
|
||||
}, conf.port)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue