feat: add hot-reloading support
Just launch and edit the pipeline.conf file.
This commit is contained in:
parent
4ba2362f5c
commit
7e80274784
@ -21,9 +21,12 @@
|
||||
#include <sys/inotify.h>
|
||||
|
||||
typedef void(*notify_callback)(pipeline_event* const);
|
||||
typedef void(*config_change_callback)();
|
||||
|
||||
// Start listening for changes to the provided file.
|
||||
// Note that the `struct inotify_event*` provided is a managed pointer.
|
||||
void listen_for_changes(const pipeline_conf* config, notify_callback callback);
|
||||
|
||||
void listen_for_config_changes(const char* config_filepath, config_change_callback callback);
|
||||
|
||||
#endif
|
||||
|
32
src/main.c
32
src/main.c
@ -28,6 +28,7 @@
|
||||
|
||||
threadpool* pool = NULL;
|
||||
char* trigger_dir = "/tmp/sci";
|
||||
bool config_file_changed = false;
|
||||
|
||||
void on_event(pipeline_event* const e) {
|
||||
if(!threadpool_add_work(pool, executor, (void*)e))
|
||||
@ -68,6 +69,18 @@ void config_interpret_line(const char* line) {
|
||||
pipeline_register(t);
|
||||
}
|
||||
|
||||
void on_config_file_changed() {
|
||||
config_file_changed = true;
|
||||
pipeline_cancel();
|
||||
log_info("config file changed, reloading...");
|
||||
}
|
||||
|
||||
void* listen_for_config_changes_thread(void* data) {
|
||||
while(1)
|
||||
listen_for_config_changes((const char*)data, &on_config_file_changed);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
cli_options args = parse(argc, argv);
|
||||
log_settings settings;
|
||||
@ -108,9 +121,18 @@ int main(int argc, char** argv) {
|
||||
if(args.environment_vars.has_value)
|
||||
set_shared_environment(args.environment_vars.value);
|
||||
|
||||
pool = threadpool_create(args.executors);
|
||||
per_line(args.config_file.value, &config_interpret_line);
|
||||
|
||||
pipeline_loop();
|
||||
threadpool_destroy(pool);
|
||||
log_info("spawning trigger thread for config file");
|
||||
pthread_t conf_listener;
|
||||
ASSERT_SYSCALL_SUCCESS(pthread_create(&conf_listener, NULL, &listen_for_config_changes_thread, (void*)args.config_file.value));
|
||||
pthread_setname_np(conf_listener, "sci-conf-listener");
|
||||
do {
|
||||
config_file_changed = false;
|
||||
worker_pool = threadpool_create(args.executors);
|
||||
per_line(args.config_file.value, &config_interpret_line);
|
||||
log_info("listening for pipeline invocations");
|
||||
pipeline_loop();
|
||||
} while(config_file_changed);
|
||||
pthread_cancel(conf_listener);
|
||||
threadpool_destroy(worker_pool);
|
||||
destroy_options(args);
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ optional_pipeline_conf pipeline_create(const char* config_line) {
|
||||
cursor += pmatch[0].rm_eo;
|
||||
}
|
||||
if(i != 4) {
|
||||
log_error("invalid configuration!\nline is invalid: \"%s\"");
|
||||
log_error("invalid configuration!");
|
||||
log_error("line is invalid: \"%s\"", config_line);
|
||||
for(int j = i-1; j >= 0; j--)
|
||||
free(opts[j]);
|
||||
return result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user