2022-04-09 09:46:07 +02:00
|
|
|
module cron
|
|
|
|
|
2022-04-13 15:24:55 +02:00
|
|
|
import log
|
|
|
|
import cron.daemon
|
2022-04-13 16:12:22 +02:00
|
|
|
import cron.expression
|
2022-04-09 09:46:07 +02:00
|
|
|
|
2022-04-12 21:23:38 +02:00
|
|
|
// cron starts a cron daemon & starts periodically scheduling builds.
|
2022-04-09 09:46:07 +02:00
|
|
|
pub fn cron(conf Config) ? {
|
2022-04-13 15:24:55 +02:00
|
|
|
// Configure logger
|
|
|
|
log_level := log.level_from_tag(conf.log_level) or {
|
2022-04-13 16:12:22 +02:00
|
|
|
return error('Invalid log level. The allowed values are FATAL, ERROR, WARN, INFO & DEBUG.')
|
2022-04-13 15:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mut logger := log.Log{
|
|
|
|
level: log_level
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.set_full_logpath(conf.log_file)
|
|
|
|
logger.log_to_console_too()
|
|
|
|
|
2022-04-13 16:12:22 +02:00
|
|
|
ce := expression.parse_expression(conf.global_schedule) or {
|
|
|
|
return error('Error while parsing global cron expression: $err.msg()')
|
|
|
|
}
|
|
|
|
|
|
|
|
mut d := daemon.init_daemon(logger, conf.address, conf.api_key, conf.base_image, ce,
|
2022-04-30 17:56:35 +02:00
|
|
|
conf.max_concurrent_builds, conf.api_update_frequency, conf.image_rebuild_frequency) ?
|
2022-04-13 16:12:22 +02:00
|
|
|
|
2022-05-01 09:14:33 +02:00
|
|
|
d.run()
|
2022-04-09 09:46:07 +02:00
|
|
|
}
|