forked from vieter-v/vieter
refactor: compile on V 0.3.2
This commit is contained in:
parent
ed29102717
commit
22fd6e395b
23 changed files with 205 additions and 203 deletions
|
|
@ -22,11 +22,11 @@ pub fn cmd() cli.Command {
|
|||
return cli.Command{
|
||||
name: 'cron'
|
||||
description: 'Start the cron service that periodically runs builds.'
|
||||
execute: fn (cmd cli.Command) ? {
|
||||
config_file := cmd.flags.get_string('config-file')?
|
||||
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)?
|
||||
execute: fn (cmd cli.Command) ! {
|
||||
config_file := cmd.flags.get_string('config-file')!
|
||||
conf := vconf.load<Config>(prefix: 'VIETER_', default_path: config_file)!
|
||||
|
||||
cron(conf)?
|
||||
cron(conf)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import os
|
|||
const log_file_name = 'vieter.cron.log'
|
||||
|
||||
// cron starts a cron daemon & starts periodically scheduling builds.
|
||||
pub fn cron(conf Config) ? {
|
||||
pub fn cron(conf Config) ! {
|
||||
// Configure logger
|
||||
log_level := log.level_from_tag(conf.log_level) or {
|
||||
return error('Invalid log level. The allowed values are FATAL, ERROR, WARN, INFO & DEBUG.')
|
||||
|
|
@ -27,7 +27,7 @@ pub fn cron(conf Config) ? {
|
|||
}
|
||||
|
||||
mut d := daemon.init_daemon(logger, conf.address, conf.api_key, conf.base_image, ce,
|
||||
conf.max_concurrent_builds, conf.api_update_frequency, conf.image_rebuild_frequency)?
|
||||
conf.max_concurrent_builds, conf.api_update_frequency, conf.image_rebuild_frequency)!
|
||||
|
||||
d.run()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ mut:
|
|||
|
||||
// init_daemon initializes a new Daemon object. It renews the targets &
|
||||
// populates the build queue for the first time.
|
||||
pub fn init_daemon(logger log.Log, address string, api_key string, base_image string, global_schedule CronExpression, max_concurrent_builds int, api_update_frequency int, image_rebuild_frequency int) ?Daemon {
|
||||
pub fn init_daemon(logger log.Log, address string, api_key string, base_image string, global_schedule CronExpression, max_concurrent_builds int, api_update_frequency int, image_rebuild_frequency int) !Daemon {
|
||||
mut d := Daemon{
|
||||
client: client.new(address, api_key)
|
||||
base_image: base_image
|
||||
|
|
@ -207,7 +207,7 @@ fn (mut d Daemon) renew_queue() {
|
|||
|
||||
// For some reason, using
|
||||
// ```v
|
||||
// for d.queue.len() > 0 && d.queue.peek() ?.timestamp < now {
|
||||
// for d.queue.len() > 0 && d.queue.peek() !.timestamp < now {
|
||||
//```
|
||||
// here causes the function to prematurely just exit, without any errors or anything, very weird
|
||||
// https://github.com/vlang/v/issues/14042
|
||||
|
|
|
|||
|
|
@ -3,33 +3,33 @@ module daemon
|
|||
import log
|
||||
|
||||
// log reate a log message with the given level
|
||||
pub fn (mut d Daemon) log(msg &string, level log.Level) {
|
||||
pub fn (mut d Daemon) log(msg string, level log.Level) {
|
||||
lock d.logger {
|
||||
d.logger.send_output(msg, level)
|
||||
}
|
||||
}
|
||||
|
||||
// lfatal create a log message with the fatal level
|
||||
pub fn (mut d Daemon) lfatal(msg &string) {
|
||||
pub fn (mut d Daemon) lfatal(msg string) {
|
||||
d.log(msg, log.Level.fatal)
|
||||
}
|
||||
|
||||
// lerror create a log message with the error level
|
||||
pub fn (mut d Daemon) lerror(msg &string) {
|
||||
pub fn (mut d Daemon) lerror(msg string) {
|
||||
d.log(msg, log.Level.error)
|
||||
}
|
||||
|
||||
// lwarn create a log message with the warn level
|
||||
pub fn (mut d Daemon) lwarn(msg &string) {
|
||||
pub fn (mut d Daemon) lwarn(msg string) {
|
||||
d.log(msg, log.Level.warn)
|
||||
}
|
||||
|
||||
// linfo create a log message with the info level
|
||||
pub fn (mut d Daemon) linfo(msg &string) {
|
||||
pub fn (mut d Daemon) linfo(msg string) {
|
||||
d.log(msg, log.Level.info)
|
||||
}
|
||||
|
||||
// ldebug create a log message with the debug level
|
||||
pub fn (mut d Daemon) ldebug(msg &string) {
|
||||
pub fn (mut d Daemon) ldebug(msg string) {
|
||||
d.log(msg, log.Level.debug)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub struct CronExpression {
|
|||
// next calculates the earliest time this cron expression is valid. It will
|
||||
// always pick a moment in the future, even if ref matches completely up to the
|
||||
// minute. This function conciously does not take gap years into account.
|
||||
pub fn (ce &CronExpression) next(ref time.Time) ?time.Time {
|
||||
pub fn (ce &CronExpression) next(ref time.Time) !time.Time {
|
||||
// If the given ref matches the next cron occurence up to the minute, it
|
||||
// will return that value. Because we always want to return a value in the
|
||||
// future, we artifically shift the ref 60 seconds to make sure we always
|
||||
|
|
@ -117,19 +117,19 @@ pub fn (ce &CronExpression) next(ref time.Time) ?time.Time {
|
|||
|
||||
// next_from_now returns the result of ce.next(ref) where ref is the result of
|
||||
// time.now().
|
||||
pub fn (ce &CronExpression) next_from_now() ?time.Time {
|
||||
pub fn (ce &CronExpression) next_from_now() !time.Time {
|
||||
return ce.next(time.now())
|
||||
}
|
||||
|
||||
// next_n returns the n next occurences of the expression, given a starting
|
||||
// time.
|
||||
pub fn (ce &CronExpression) next_n(ref time.Time, n int) ?[]time.Time {
|
||||
pub fn (ce &CronExpression) next_n(ref time.Time, n int) ![]time.Time {
|
||||
mut times := []time.Time{cap: n}
|
||||
|
||||
times << ce.next(ref)?
|
||||
times << ce.next(ref)!
|
||||
|
||||
for i in 1 .. n {
|
||||
times << ce.next(times[i - 1])?
|
||||
times << ce.next(times[i - 1])!
|
||||
}
|
||||
|
||||
return times
|
||||
|
|
@ -137,7 +137,7 @@ pub fn (ce &CronExpression) next_n(ref time.Time, n int) ?[]time.Time {
|
|||
|
||||
// parse_range parses a given string into a range of sorted integers, if
|
||||
// possible.
|
||||
fn parse_range(s string, min int, max int, mut bitv []bool) ? {
|
||||
fn parse_range(s string, min int, max int, mut bitv []bool) ! {
|
||||
mut start := min
|
||||
mut end := max
|
||||
mut interval := 1
|
||||
|
|
@ -228,11 +228,11 @@ fn bitv_to_ints(bitv []bool, min int) []int {
|
|||
|
||||
// parse_part parses a given part of a cron expression & returns the
|
||||
// corresponding array of ints.
|
||||
fn parse_part(s string, min int, max int) ?[]int {
|
||||
fn parse_part(s string, min int, max int) ![]int {
|
||||
mut bitv := []bool{len: max - min + 1, init: false}
|
||||
|
||||
for range in s.split(',') {
|
||||
parse_range(range, min, max, mut bitv)?
|
||||
parse_range(range, min, max, mut bitv)!
|
||||
}
|
||||
|
||||
return bitv_to_ints(bitv, min)
|
||||
|
|
@ -240,7 +240,7 @@ fn parse_part(s string, min int, max int) ?[]int {
|
|||
|
||||
// parse_expression parses an entire cron expression string into a
|
||||
// CronExpression object, if possible.
|
||||
pub fn parse_expression(exp string) ?CronExpression {
|
||||
pub fn parse_expression(exp string) !CronExpression {
|
||||
// The filter allows for multiple spaces between parts
|
||||
mut parts := exp.split(' ').filter(it != '')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue