@@ -409,6 +409,42 @@ void job_state_unpause_cb (flux_t *h, flux_msg_handler_t *mh,
409409 flux_log_error (h , "error responding to unpause request" );
410410}
411411
412+ static int store_eventlog_entry (struct job_state_ctx * jsctx ,
413+ struct job * job ,
414+ json_t * entry )
415+ {
416+ char * s = json_dumps (entry , 0 );
417+ int rv = -1 ;
418+
419+ /* entry should have been verified via eventlog_entry_parse()
420+ * earlier */
421+ assert (s );
422+
423+ if (!job -> eventlog ) {
424+ job -> eventlog_len = strlen (s ) + 2 ; /* +2 for \n and \0 */
425+ if (!(job -> eventlog = calloc (1 , job -> eventlog_len ))) {
426+ flux_log_error (jsctx -> h , "calloc" );
427+ goto error ;
428+
429+ }
430+ strcpy (job -> eventlog , s );
431+ strcat (job -> eventlog , "\n" );
432+ }
433+ else {
434+ job -> eventlog_len += strlen (s ) + 1 ; /* +1 for \n */
435+ if (!(job -> eventlog = realloc (job -> eventlog , job -> eventlog_len ))) {
436+ flux_log_error (jsctx -> h , "realloc" );
437+ goto error ;
438+ }
439+ strcat (job -> eventlog , s );
440+ strcat (job -> eventlog , "\n" );
441+ }
442+ rv = 0 ;
443+ error :
444+ free (s );
445+ return rv ;
446+ }
447+
412448static int job_transition_state (struct job_state_ctx * jsctx ,
413449 struct job * job ,
414450 flux_job_state_t newstate ,
@@ -487,12 +523,17 @@ static int journal_submit_event (struct job_state_ctx *jsctx,
487523 struct job * job ,
488524 flux_jobid_t id ,
489525 double timestamp ,
526+ json_t * entry ,
490527 json_t * context ,
491528 json_t * jobspec )
492529{
493530 if (!job ) {
494531 if (!(job = job_create (jsctx -> h , id )))
495532 return -1 ;
533+ if (store_eventlog_entry (jsctx , job , entry ) < 0 ) {
534+ job_destroy (job );
535+ return -1 ;
536+ }
496537 if (jobspec )
497538 job -> jobspec = json_incref (jobspec );
498539 if (zhashx_insert (jsctx -> index , & job -> id , job ) < 0 ) {
@@ -895,11 +936,17 @@ static int journal_process_event (struct job_state_ctx *jsctx,
895936 return 0 ;
896937 }
897938
939+ if (job && job -> eventlog ) {
940+ if (store_eventlog_entry (jsctx , job , event ) < 0 )
941+ return -1 ;
942+ }
943+
898944 if (streq (name , "submit" )) {
899945 if (journal_submit_event (jsctx ,
900946 job ,
901947 id ,
902948 timestamp ,
949+ event ,
903950 context ,
904951 jobspec ) < 0 )
905952 return -1 ;
0 commit comments