diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-12-07 18:15:27 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-12-07 18:15:27 +0100 |
commit | 645bd551dcfb609ce4b57a205bbf1c3e129d4ef3 (patch) | |
tree | 9e89afea2e74628bb0350d2bfefb2903957badb1 /src/master.c | |
parent | 5f1f7c844741a8c55705e8460fca54024c7d5102 (diff) | |
download | biruda-645bd551dcfb609ce4b57a205bbf1c3e129d4ef3.tar.gz biruda-645bd551dcfb609ce4b57a205bbf1c3e129d4ef3.tar.bz2 |
added started, stopped messages for worker
Diffstat (limited to 'src/master.c')
-rw-r--r-- | src/master.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/master.c b/src/master.c index 387fe5f..a3d98b1 100644 --- a/src/master.c +++ b/src/master.c @@ -382,6 +382,74 @@ static int master_output_write( const char *spool_dir, json_object *obj ) return 0; } +static int master_output_write_started( const char *spool_dir, json_object *obj ) +{ + json_object *worker_obj; + json_object_object_get_ex( obj, "worker", &worker_obj ); + const char *name = json_object_get_string( worker_obj ); + + worker_t *w = worker_by_name( name ); + + if( w == NULL ) return 0; + + execution_worker_data_t *wed = (execution_worker_data_t *)w->execution_data; + + if( wed->spool_file == NULL ) { + master_output_init( spool_dir, name ); + if( wed->spool_file == NULL ) return 0; + } + + json_object *pid_obj; + json_object_object_get_ex( obj, "pid", &pid_obj ); + int pid = json_object_get_int( pid_obj ); + + json_object *ts_obj; + json_object_object_get_ex( obj, "timestamp", &ts_obj ); + time_t ts = json_object_get_int( ts_obj ); + + char line[1024]; + snprintf( line, sizeof( line ), "%lu %s --- STARTED %d ---\n", ts, name, pid ); + + fputs( line, wed->spool_file ); + fflush( wed->spool_file ); + + return 0; +} + +static int master_output_write_terminated( const char *spool_dir, json_object *obj ) +{ + json_object *worker_obj; + json_object_object_get_ex( obj, "worker", &worker_obj ); + const char *name = json_object_get_string( worker_obj ); + + worker_t *w = worker_by_name( name ); + + if( w == NULL ) return 0; + + execution_worker_data_t *wed = (execution_worker_data_t *)w->execution_data; + + if( wed->spool_file == NULL ) { + master_output_init( spool_dir, name ); + if( wed->spool_file == NULL ) return 0; + } + + json_object *pid_obj; + json_object_object_get_ex( obj, "pid", &pid_obj ); + int pid = json_object_get_int( pid_obj ); + + json_object *ts_obj; + json_object_object_get_ex( obj, "timestamp", &ts_obj ); + time_t ts = json_object_get_int( ts_obj ); + + char line[1024]; + snprintf( line, sizeof( line ), "%lu %s --- STOPPED %d ---\n", ts, name, pid ); + + fputs( line, wed->spool_file ); + fflush( wed->spool_file ); + + return 0; +} + static void *master_func( void *thread_data ) { master_thread_data_t *tdata = (master_thread_data_t *)thread_data; @@ -496,6 +564,10 @@ NEXT_COMMAND: json_object_object_get_ex( recv_obj, "worker", &worker_obj ); const char *worker = json_object_get_string( worker_obj ); master_output_free( worker ); + } else if( strcmp( op, "created" ) == 0 ) { + master_output_write_started( tdata->spool_dir, recv_obj ); + } else if( strcmp( op, "terminated" ) == 0 ) { + master_output_write_terminated( tdata->spool_dir, recv_obj ); } else if( strcmp( op, "output" ) == 0 ) { master_output_write( tdata->spool_dir, recv_obj ); } else { |