forked from vieter-v/vieter
more wip
parent
f7ca005ad5
commit
722acb8ab3
|
|
@ -19,6 +19,7 @@ const (
|
||||||
pub struct BuildConfig {
|
pub struct BuildConfig {
|
||||||
pub:
|
pub:
|
||||||
id int
|
id int
|
||||||
|
target_id int
|
||||||
kind string
|
kind string
|
||||||
url string
|
url string
|
||||||
branch string
|
branch string
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
module server
|
module server
|
||||||
|
|
||||||
import web
|
import web
|
||||||
import web.response { new_response }
|
import web.response { new_data_response, new_response }
|
||||||
// import db
|
|
||||||
import time
|
import time
|
||||||
|
import build { BuildConfig }
|
||||||
// import os
|
// import os
|
||||||
// import util
|
// import util
|
||||||
// import models { BuildLog, BuildLogFilter }
|
// import models { BuildLog, BuildLogFilter }
|
||||||
|
|
@ -19,13 +19,21 @@ fn (mut app App) v1_poll_build_queue() web.Result {
|
||||||
}
|
}
|
||||||
max := max_str.int()
|
max := max_str.int()
|
||||||
|
|
||||||
|
mut out := []BuildConfig{}
|
||||||
mut out := []
|
|
||||||
|
|
||||||
now := time.now()
|
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
|
data_dir string
|
||||||
api_key string
|
api_key string
|
||||||
default_arch string
|
default_arch string
|
||||||
|
global_schedule string = '0 3'
|
||||||
port int = 8000
|
port int = 8000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import db
|
||||||
import datatypes { MinHeap }
|
import datatypes { MinHeap }
|
||||||
import build { BuildConfig }
|
import build { BuildConfig }
|
||||||
import time
|
import time
|
||||||
|
import cron.expression
|
||||||
|
|
||||||
const (
|
const (
|
||||||
log_file_name = 'vieter.log'
|
log_file_name = 'vieter.log'
|
||||||
|
|
@ -19,9 +20,8 @@ const (
|
||||||
|
|
||||||
struct ScheduledBuild {
|
struct ScheduledBuild {
|
||||||
pub:
|
pub:
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
target_id int
|
config BuildConfig
|
||||||
build_config BuildConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overloaded operator for comparing ScheduledBuild objects
|
// Overloaded operator for comparing ScheduledBuild objects
|
||||||
|
|
@ -34,9 +34,40 @@ struct App {
|
||||||
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>
|
// Keys are the various architectures for packages
|
||||||
db db.VieterDb
|
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
|
// server starts the web server & starts listening for requests
|
||||||
|
|
@ -93,6 +124,6 @@ pub fn server(conf Config) ! {
|
||||||
conf: conf
|
conf: conf
|
||||||
repo: repo
|
repo: repo
|
||||||
db: db
|
db: db
|
||||||
build_queue: MinHeap<ScheduledBuild>{}
|
build_queues: map[string]MinHeap<ScheduledBuild>{}
|
||||||
}, conf.port)
|
}, conf.port)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue