forked from vieter-v/vieter
Compare commits
No commits in common. "a9ad3088bbfd0366ffae6e8174c23c0808a0a385" and "8b72a9fc0f0dd88abf41d5d4f73c5a34ac4cb4ef" have entirely different histories.
a9ad3088bb
...
8b72a9fc0f
|
|
@ -149,17 +149,3 @@ target | id of target this build is for
|
||||||
### Request body
|
### Request body
|
||||||
|
|
||||||
Plaintext contents of the build log.
|
Plaintext contents of the build log.
|
||||||
|
|
||||||
## Remove a build log
|
|
||||||
|
|
||||||
Remove a build log from the server.
|
|
||||||
|
|
||||||
### HTTP Request
|
|
||||||
|
|
||||||
`DELETE /api/v1/logs/:id`
|
|
||||||
|
|
||||||
### URL Parameters
|
|
||||||
|
|
||||||
Parameter | Description
|
|
||||||
--------- | -----------
|
|
||||||
id | id of log to remove
|
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,6 @@ configuration variable required for each command.
|
||||||
* Git repositories added without an `arch` value use this value instead.
|
* Git repositories added without an `arch` value use this value instead.
|
||||||
* `port`: HTTP port to run on
|
* `port`: HTTP port to run on
|
||||||
* Default: `8000`
|
* Default: `8000`
|
||||||
* `max_log_age`: maximum age of logs (in days). Logs older than this will get
|
|
||||||
cleaned by the log removal daemon every 24 hours. If set to a negative value,
|
|
||||||
no logs are ever removed. The age of logs is determined by the time the build
|
|
||||||
was started.
|
|
||||||
* Default: `-1`
|
|
||||||
|
|
||||||
### `vieter cron`
|
### `vieter cron`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,3 @@ pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time t
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove_build_log removes the build log with the given id from the server.
|
|
||||||
pub fn (c &Client) remove_build_log(id int) !string {
|
|
||||||
data := c.send_request<string>(.delete, '/api/v1/logs/$id', {})!
|
|
||||||
|
|
||||||
return data.data
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -138,18 +138,6 @@ pub fn cmd() cli.Command {
|
||||||
list(conf, filter, raw)!
|
list(conf, filter, raw)!
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cli.Command{
|
|
||||||
name: 'remove'
|
|
||||||
required_args: 1
|
|
||||||
usage: 'id'
|
|
||||||
description: 'Remove a build log that matches the given id.'
|
|
||||||
execute: fn (cmd cli.Command) ! {
|
|
||||||
config_file := cmd.flags.get_string('config-file')!
|
|
||||||
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
|
|
||||||
|
|
||||||
remove(conf, cmd.args[0])!
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cli.Command{
|
cli.Command{
|
||||||
name: 'info'
|
name: 'info'
|
||||||
required_args: 1
|
required_args: 1
|
||||||
|
|
@ -216,9 +204,3 @@ fn content(conf Config, id int) ! {
|
||||||
|
|
||||||
println(content)
|
println(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove removes a build log from the server's list.
|
|
||||||
fn remove(conf Config, id string) ! {
|
|
||||||
c := client.new(conf.address, conf.api_key)
|
|
||||||
c.remove_build_log(id.int())!
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -124,22 +124,3 @@ fn (mut app App) v1_post_log() web.Result {
|
||||||
|
|
||||||
return app.json(.ok, new_data_response(log_id))
|
return app.json(.ok, new_data_response(log_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// v1_delete_log allows removing a build log from the system.
|
|
||||||
['/api/v1/logs/:id'; auth; delete]
|
|
||||||
fn (mut app App) v1_delete_log(id int) web.Result {
|
|
||||||
log := app.db.get_build_log(id) or { return app.status(.not_found) }
|
|
||||||
file_name := log.start_time.custom_format('YYYY-MM-DD_HH-mm-ss')
|
|
||||||
full_path := os.join_path(app.conf.data_dir, logs_dir_name, log.target_id.str(), log.arch,
|
|
||||||
file_name)
|
|
||||||
|
|
||||||
os.rm(full_path) or {
|
|
||||||
app.lerror('Failed to remove log file $full_path: $err.msg()')
|
|
||||||
|
|
||||||
return app.status(.internal_server_error)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.db.delete_build_log(id)
|
|
||||||
|
|
||||||
return app.status(.ok)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ pub:
|
||||||
global_schedule string = '0 3'
|
global_schedule string = '0 3'
|
||||||
port int = 8000
|
port int = 8000
|
||||||
base_image string = 'archlinux:base-devel'
|
base_image string = 'archlinux:base-devel'
|
||||||
max_log_age int = -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cmd returns the cli submodule that handles starting the server
|
// cmd returns the cli submodule that handles starting the server
|
||||||
|
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
module server
|
|
||||||
|
|
||||||
import time
|
|
||||||
import models { BuildLog }
|
|
||||||
import os
|
|
||||||
|
|
||||||
const log_removal_frequency = 24 * time.hour
|
|
||||||
|
|
||||||
// log_removal_daemon removes old build logs every `log_removal_frequency`.
|
|
||||||
fn (mut app App) log_removal_daemon() {
|
|
||||||
mut start_time := time.Time{}
|
|
||||||
|
|
||||||
for {
|
|
||||||
start_time = time.now()
|
|
||||||
|
|
||||||
mut too_old_timestamp := time.now().add_days(-app.conf.max_log_age)
|
|
||||||
|
|
||||||
app.linfo('Cleaning logs before $too_old_timestamp')
|
|
||||||
|
|
||||||
mut offset := u64(0)
|
|
||||||
mut logs := []BuildLog{}
|
|
||||||
mut counter := 0
|
|
||||||
mut failed := 0
|
|
||||||
|
|
||||||
// Remove old logs
|
|
||||||
for {
|
|
||||||
logs = app.db.get_build_logs(before: too_old_timestamp, offset: offset, limit: 50)
|
|
||||||
|
|
||||||
for log in logs {
|
|
||||||
file_name := log.start_time.custom_format('YYYY-MM-DD_HH-mm-ss')
|
|
||||||
full_path := os.join_path(app.conf.data_dir, logs_dir_name, log.target_id.str(),
|
|
||||||
log.arch, file_name)
|
|
||||||
os.rm(full_path) or {
|
|
||||||
app.lerror('Failed to remove log file $full_path: $err.msg()')
|
|
||||||
failed += 1
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
app.db.delete_build_log(log.id)
|
|
||||||
|
|
||||||
counter += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if logs.len < 50 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += 50
|
|
||||||
}
|
|
||||||
|
|
||||||
app.linfo('Cleaned $counter logs ($failed failed)')
|
|
||||||
|
|
||||||
// Sleep until the next cycle
|
|
||||||
time.sleep(start_time.add_days(1) - time.now())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -108,9 +108,5 @@ pub fn server(conf Config) ! {
|
||||||
util.exit_with_message(1, 'Failed to inialize job queue: $err.msg()')
|
util.exit_with_message(1, 'Failed to inialize job queue: $err.msg()')
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.max_log_age > 0 {
|
|
||||||
go app.log_removal_daemon()
|
|
||||||
}
|
|
||||||
|
|
||||||
web.run(app, conf.port)
|
web.run(app, conf.port)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,3 @@ address = "http://localhost:8000"
|
||||||
api_update_frequency = 2
|
api_update_frequency = 2
|
||||||
image_rebuild_frequency = 1
|
image_rebuild_frequency = 1
|
||||||
max_concurrent_builds = 3
|
max_concurrent_builds = 3
|
||||||
max_log_age = 64
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue