forked from vieter-v/vieter
chore: ran v fmt for v 0.3.3 changes
This commit is contained in:
parent
e10b450abd
commit
b3a119f221
37 changed files with 179 additions and 175 deletions
|
|
@ -13,7 +13,7 @@ import models { BuildLog, BuildLogFilter }
|
|||
// optionally be added to limit the list of build logs to that repository.
|
||||
['/api/v1/logs'; auth; get; markused]
|
||||
fn (mut app App) v1_get_logs() web.Result {
|
||||
filter := models.from_params<BuildLogFilter>(app.query) or {
|
||||
filter := models.from_params[BuildLogFilter](app.query) or {
|
||||
return app.json(.bad_request, new_response('Invalid query parameters.'))
|
||||
}
|
||||
logs := app.db.get_build_logs(filter)
|
||||
|
|
@ -101,7 +101,7 @@ fn (mut app App) v1_post_log() web.Result {
|
|||
// Create the logs directory of it doesn't exist
|
||||
if !os.exists(os.dir(log_file_path)) {
|
||||
os.mkdir_all(os.dir(log_file_path)) or {
|
||||
app.lerror('Error while creating log file: $err.msg()')
|
||||
app.lerror('Error while creating log file: ${err.msg()}')
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ fn (mut app App) v1_post_log() web.Result {
|
|||
|
||||
if length := app.req.header.get(.content_length) {
|
||||
util.reader_to_file(mut app.reader, length.int(), log_file_path) or {
|
||||
app.lerror('An error occured while receiving logs: $err.msg()')
|
||||
app.lerror('An error occured while receiving logs: ${err.msg()}')
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ fn (mut app App) v1_delete_log(id int) web.Result {
|
|||
full_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
|
||||
|
||||
os.rm(full_path) or {
|
||||
app.lerror('Failed to remove log file $full_path: $err.msg()')
|
||||
app.lerror('Failed to remove log file ${full_path}: ${err.msg()}')
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import models { Target, TargetArch, TargetFilter }
|
|||
// v1_get_targets returns the current list of targets.
|
||||
['/api/v1/targets'; auth; get; markused]
|
||||
fn (mut app App) v1_get_targets() web.Result {
|
||||
filter := models.from_params<TargetFilter>(app.query) or {
|
||||
filter := models.from_params[TargetFilter](app.query) or {
|
||||
return app.json(.bad_request, new_response('Invalid query parameters.'))
|
||||
}
|
||||
mut iter := app.db.targets(filter)
|
||||
|
|
@ -35,7 +35,7 @@ fn (mut app App) v1_post_target() web.Result {
|
|||
params['arch'] = app.conf.default_arch
|
||||
}
|
||||
|
||||
mut new_target := models.from_params<Target>(params) or {
|
||||
mut new_target := models.from_params[Target](params) or {
|
||||
return app.json(.bad_request, new_response(err.msg()))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub fn cmd() cli.Command {
|
|||
description: 'Start the Vieter server.'
|
||||
execute: fn (cmd cli.Command) ! {
|
||||
config_file := cmd.flags.get_string('config-file')!
|
||||
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
|
||||
conf := vconf.load[Config](prefix: 'VIETER_', default_path: config_file)!
|
||||
|
||||
server(conf)!
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
|
|||
for {
|
||||
mut too_old_timestamp := time.now().add_days(-app.conf.max_log_age)
|
||||
|
||||
app.linfo('Cleaning logs before $too_old_timestamp')
|
||||
app.linfo('Cleaning logs before ${too_old_timestamp}')
|
||||
|
||||
mut logs := []BuildLog{}
|
||||
mut counter := 0
|
||||
|
|
@ -29,7 +29,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
|
|||
log_file_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
|
||||
|
||||
os.rm(log_file_path) or {
|
||||
app.lerror('Failed to remove log file $log_file_path: $err.msg()')
|
||||
app.lerror('Failed to remove log file ${log_file_path}: ${err.msg()}')
|
||||
failed += 1
|
||||
|
||||
continue
|
||||
|
|
@ -44,7 +44,7 @@ fn (mut app App) log_removal_daemon(schedule &cron.Expression) {
|
|||
}
|
||||
}
|
||||
|
||||
app.linfo('Cleaned $counter logs ($failed failed)')
|
||||
app.linfo('Cleaned ${counter} logs (${failed} failed)')
|
||||
|
||||
// Sleep until the next cycle
|
||||
next_time := schedule.next_from_now()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ fn (mut app App) get_repo_file(repo string, arch string, filename string) web.Re
|
|||
|
||||
// There's no point in having the ability to serve db archives with wrong
|
||||
// filenames
|
||||
if db_exts.any(filename == '$repo$it') {
|
||||
if db_exts.any(filename == '${repo}${it}') {
|
||||
full_path = os.join_path(app.repo.repos_dir, repo, arch, filename)
|
||||
|
||||
// repo-add does this using symlinks, but we just change the requested
|
||||
|
|
@ -62,19 +62,19 @@ fn (mut app App) put_package(repo string) web.Result {
|
|||
// Generate a random filename for the temp file
|
||||
pkg_path = os.join_path_single(app.repo.pkg_dir, rand.uuid_v4())
|
||||
|
||||
app.ldebug("Uploading $length bytes (${util.pretty_bytes(length.int())}) to '$pkg_path'.")
|
||||
app.ldebug("Uploading ${length} bytes (${util.pretty_bytes(length.int())}) to '${pkg_path}'.")
|
||||
|
||||
// This is used to time how long it takes to upload a file
|
||||
mut sw := time.new_stopwatch(time.StopWatchOptions{ auto_start: true })
|
||||
|
||||
util.reader_to_file(mut app.reader, length.int(), pkg_path) or {
|
||||
app.lwarn("Failed to upload '$pkg_path'")
|
||||
app.lwarn("Failed to upload '${pkg_path}'")
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
||||
sw.stop()
|
||||
app.ldebug("Upload of '$pkg_path' completed in ${sw.elapsed().seconds():.3}s.")
|
||||
app.ldebug("Upload of '${pkg_path}' completed in ${sw.elapsed().seconds():.3}s.")
|
||||
} else {
|
||||
app.lwarn('Tried to upload package without specifying a Content-Length.')
|
||||
|
||||
|
|
@ -83,14 +83,14 @@ fn (mut app App) put_package(repo string) web.Result {
|
|||
}
|
||||
|
||||
res := app.repo.add_pkg_from_path(repo, pkg_path) or {
|
||||
app.lerror('Error while adding package: $err.msg()')
|
||||
app.lerror('Error while adding package: ${err.msg()}')
|
||||
|
||||
os.rm(pkg_path) or { app.lerror("Failed to remove download '$pkg_path': $err.msg()") }
|
||||
os.rm(pkg_path) or { app.lerror("Failed to remove download '${pkg_path}': ${err.msg()}") }
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
||||
app.linfo("Added '$res.name-$res.version' to '$repo (${res.archs.join(',')})'.")
|
||||
app.linfo("Added '${res.name}-${res.version}' to '${repo} (${res.archs.join(',')})'.")
|
||||
|
||||
return app.json(.ok, new_data_response(res))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@ import web
|
|||
['/:repo/:arch/:pkg'; auth; delete; markused]
|
||||
fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result {
|
||||
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
|
||||
app.lerror('Error while deleting package: $err.msg()')
|
||||
app.lerror('Error while deleting package: ${err.msg()}')
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
||||
if res {
|
||||
app.linfo("Removed package '$pkg' from '$repo/$arch'")
|
||||
app.linfo("Removed package '${pkg}' from '${repo}/${arch}'")
|
||||
|
||||
return app.status(.ok)
|
||||
} else {
|
||||
app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.")
|
||||
app.linfo("Tried removing package '${pkg}' from '${repo}/${arch}', but it doesn't exist.")
|
||||
|
||||
return app.status(.not_found)
|
||||
}
|
||||
|
|
@ -26,17 +26,17 @@ fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result
|
|||
['/:repo/:arch'; auth; delete; markused]
|
||||
fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
|
||||
res := app.repo.remove_arch_repo(repo, arch) or {
|
||||
app.lerror('Error while deleting arch-repo: $err.msg()')
|
||||
app.lerror('Error while deleting arch-repo: ${err.msg()}')
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
||||
if res {
|
||||
app.linfo("Removed arch-repo '$repo/$arch'")
|
||||
app.linfo("Removed arch-repo '${repo}/${arch}'")
|
||||
|
||||
return app.status(.ok)
|
||||
} else {
|
||||
app.linfo("Tried removing '$repo/$arch', but it doesn't exist.")
|
||||
app.linfo("Tried removing '${repo}/${arch}', but it doesn't exist.")
|
||||
|
||||
return app.status(.not_found)
|
||||
}
|
||||
|
|
@ -46,17 +46,17 @@ fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
|
|||
['/:repo'; auth; delete; markused]
|
||||
fn (mut app App) delete_repo(repo string) web.Result {
|
||||
res := app.repo.remove_repo(repo) or {
|
||||
app.lerror('Error while deleting repo: $err.msg()')
|
||||
app.lerror('Error while deleting repo: ${err.msg()}')
|
||||
|
||||
return app.status(.internal_server_error)
|
||||
}
|
||||
|
||||
if res {
|
||||
app.linfo("Removed repo '$repo'")
|
||||
app.linfo("Removed repo '${repo}'")
|
||||
|
||||
return app.status(.ok)
|
||||
} else {
|
||||
app.linfo("Tried removing '$repo', but it doesn't exist.")
|
||||
app.linfo("Tried removing '${repo}', but it doesn't exist.")
|
||||
|
||||
return app.status(.not_found)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,11 +44,11 @@ pub fn server(conf Config) ! {
|
|||
}
|
||||
|
||||
global_ce := cron.parse_expression(conf.global_schedule) or {
|
||||
util.exit_with_message(1, 'Invalid global cron expression: $err.msg()')
|
||||
util.exit_with_message(1, 'Invalid global cron expression: ${err.msg()}')
|
||||
}
|
||||
|
||||
log_removal_ce := cron.parse_expression(conf.log_removal_schedule) or {
|
||||
util.exit_with_message(1, 'Invalid log removal cron expression: $err.msg()')
|
||||
util.exit_with_message(1, 'Invalid log removal cron expression: ${err.msg()}')
|
||||
}
|
||||
|
||||
// Configure logger
|
||||
|
|
@ -89,7 +89,7 @@ pub fn server(conf Config) ! {
|
|||
|
||||
db_file := os.join_path_single(conf.data_dir, server.db_file_name)
|
||||
db := db.init(db_file) or {
|
||||
util.exit_with_message(1, 'Failed to initialize database: $err.msg()')
|
||||
util.exit_with_message(1, 'Failed to initialize database: ${err.msg()}')
|
||||
}
|
||||
|
||||
mut collector := if conf.collect_metrics {
|
||||
|
|
@ -97,9 +97,9 @@ pub fn server(conf Config) ! {
|
|||
} else {
|
||||
&metrics.MetricsCollector(metrics.new_null_collector())
|
||||
}
|
||||
|
||||
collector.histogram_buckets_set('http_requests_duration_seconds', [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5,
|
||||
10] )
|
||||
|
||||
collector.histogram_buckets_set('http_requests_duration_seconds', [0.001, 0.005, 0.01, 0.05,
|
||||
0.1, 0.5, 1, 5, 10])
|
||||
|
||||
mut app := &App{
|
||||
logger: logger
|
||||
|
|
@ -111,11 +111,11 @@ pub fn server(conf Config) ! {
|
|||
job_queue: build.new_job_queue(global_ce, conf.base_image)
|
||||
}
|
||||
app.init_job_queue() or {
|
||||
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(log_removal_ce)
|
||||
spawn app.log_removal_daemon(log_removal_ce)
|
||||
}
|
||||
|
||||
web.run(app, conf.port)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue