static void fixup_newjob_event (flux_t *h, int64_t nj) { json_object *ss = NULL; json_object *jcb = NULL; int64_t js = J_NULL; char *key = xasprintf ("%"PRId64, nj); jscctx_t *ctx = getctx (h); /* We fix up ordering problem only when new job event hasn't been reported through a kvs watch */ jcb = Jnew (); ss = Jnew (); Jadd_int64 (jcb, JSC_JOBID, nj); Jadd_int64 (ss, JSC_STATE_PAIR_OSTATE , (int64_t) js); Jadd_int64 (ss, JSC_STATE_PAIR_NSTATE, (int64_t) js); json_object_object_add (jcb, JSC_STATE_PAIR, ss); if (zhash_insert (ctx->active_jobs, key, (void *)(intptr_t)js) < 0) { flux_log (h, LOG_ERR, "new_job_cb: inserting a job to hash failed"); goto done; } if (invoke_cbs (h, nj, jcb, 0) < 0) { flux_log (h, LOG_ERR, "makeup_newjob_event: failed to invoke callbacks"); goto done; } done: Jput (jcb); free (key); return; }
static void job_state_cb (flux_t h, flux_msg_handler_t *w, const flux_msg_t *msg, void *arg) { int64_t jobid = -1; json_object *o = NULL; const char *topic = NULL; const char *json_str = NULL; const char *state = NULL; int len = 12; if (flux_msg_get_topic (msg, &topic) < 0) goto done; if (flux_event_decode (msg, NULL, &json_str) < 0 || !(o = Jfromstr (json_str)) || !Jget_int64 (o, "lwj", &jobid)) { flux_log (h, LOG_ERR, "%s: bad message", __FUNCTION__); goto done; } if (strncmp (topic, "jsc", 3) == 0) len = 10; state = topic + len; if (strcmp (state, jsc_job_num2state (J_RESERVED)) == 0) fixup_newjob_event (h, jobid); if (invoke_cbs (h, jobid, get_update_jcb (h, jobid, state), 0) < 0) flux_log (h, LOG_ERR, "job_state_cb: failed to invoke callbacks"); if (job_is_finished (state)) delete_jobinfo (h, jobid); done: return; }
static int new_job_cb (const char *key, int64_t val, void *arg, int errnum) { int64_t nj = 0; int64_t js = 0; JSON ss = NULL; JSON jcb = NULL; char k[20] = {'\0'}; char path[20] = {'\0'}; flux_t h = (flux_t) arg; jscctx_t *ctx = getctx (h); if (ctx->first_time == 1) { /* watch is invoked immediately and we shouldn't * rely on that event at all. */ ctx->first_time = 0; return 0; } if (chk_errnum (h, errnum) < 0) return 0; flux_log (h, LOG_DEBUG, "new_job_cb invoked: key(%s), val(%ld)", key, val); js = J_NULL; nj = val-1; snprintf (k, 20, "%ld", nj); snprintf (path, 20, "lwj.%ld", nj); if (zhash_insert (ctx->active_jobs, k, (void *)(intptr_t)js) < 0) { flux_log (h, LOG_ERR, "new_job_cb: inserting a job to hash failed"); goto done; } flux_log (h, LOG_DEBUG, "jobstate_hdlr registered"); jcb = Jnew (); ss = Jnew (); Jadd_int64 (jcb, JSC_JOBID, nj); Jadd_int64 (ss, JSC_STATE_PAIR_OSTATE , (int64_t) js); Jadd_int64 (ss, JSC_STATE_PAIR_NSTATE, (int64_t) js); json_object_object_add (jcb, JSC_STATE_PAIR, ss); if (invoke_cbs (h, nj, jcb, errnum) < 0) { flux_log (h, LOG_ERR, "new_job_cb: failed to invoke callbacks"); } if (reg_jobstate_hdlr (h, path, job_state_cb) == -1) { flux_log (h, LOG_ERR, "new_job_cb: reg_jobstate_hdlr: %s", strerror (errno)); } done: /* always return 0 so that reactor won't return */ return 0; }
static int job_state_cb (const char *key, const char *val, void *arg, int errnum) { int64_t jobid = -1; flux_t h = (flux_t) arg; if (chk_errnum (h, errnum) < 0) flux_log (h, LOG_ERR, "job_state_cb: key(%s), val(%s)", key, val); else if (parse_jobid (key, &jobid) != 0) flux_log (h, LOG_ERR, "job_state_cb: key ill-formed"); else if (invoke_cbs (h, jobid, get_update_jcb (h, jobid, val), errnum) < 0) flux_log (h, LOG_ERR, "job_state_cb: failed to invoke callbacks"); /* always return 0 so that reactor will not return */ return 0; }
static void job_state_cb (flux_t *h, flux_msg_handler_t *mh, const flux_msg_t *msg, void *arg) { json_object *jcb = NULL; int64_t jobid = -1; const char *topic = NULL; const char *state = NULL; const char *kvs_path = NULL; int len = 12; if (flux_msg_get_topic (msg, &topic) < 0) goto done; if (flux_event_unpack (msg, NULL, "{ s:I }", "lwj", &jobid) < 0) { flux_log (h, LOG_ERR, "%s: bad message", __FUNCTION__); goto done; } if (!flux_event_unpack (msg, NULL, "{ s:s }", "kvs_path", &kvs_path)) { if (jscctx_add_jobid_path (getctx (h), jobid, kvs_path) < 0) flux_log_error (h, "jscctx_add_jobid_path"); } if (strncmp (topic, "jsc", 3) == 0) len = 10; state = topic + len; if (strcmp (state, jsc_job_num2state (J_RESERVED)) == 0) fixup_newjob_event (h, jobid); if (invoke_cbs (h, jobid, jcb = get_update_jcb (h, jobid, state), 0) < 0) flux_log (h, LOG_ERR, "job_state_cb: failed to invoke callbacks"); if (job_is_finished (state)) delete_jobinfo (h, jobid); done: Jput (jcb); return; }