static int update_state (flux_t h, int64_t j, JSON o) { int rc = -1; int64_t st = 0; char *key; if (!Jget_int64 (o, JSC_STATE_PAIR_NSTATE, &st)) return -1; if ((st >= J_FOR_RENT) || (st < J_NULL)) return -1; key = xasprintf ("lwj.%"PRId64".state", j); if (kvs_put_string (h, key, jsc_job_num2state ((job_state_t)st)) < 0) flux_log_error (h, "update %s", key); else if (kvs_commit (h) < 0) flux_log_error (h, "commit %s", key); else { flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new state: %s", j, jsc_job_num2state ((job_state_t)st)); rc = 0; } free (key); if (send_state_event (h, st, j) < 0) flux_log_error (h, "send state event"); return rc; }
static int update_state (flux_t *h, int64_t j, json_object *o) { int rc = -1; int64_t st = 0; char *key = NULL; flux_kvs_txn_t *txn = NULL; flux_future_t *f = NULL; if (!Jget_int64 (o, JSC_STATE_PAIR_NSTATE, &st)) goto done; if ((st >= J_FOR_RENT) || (st < J_NULL)) goto done; if (!(key = lwj_key (h, j, ".state"))) goto done; if (!(txn = flux_kvs_txn_create ())) { flux_log_error (h, "txn_create"); goto done; } if (flux_kvs_txn_pack (txn, 0, key, "s", jsc_job_num2state ((job_state_t)st)) < 0) { flux_log_error (h, "update %s", key); goto done; } if (!(f = flux_kvs_commit (h, 0, txn)) || flux_future_get (f, NULL) < 0) { flux_log_error (h, "commit %s", key); goto done; } flux_log (h, LOG_DEBUG, "job (%"PRId64") assigned new state: %s", j, jsc_job_num2state ((job_state_t)st)); rc = 0; if (send_state_event (h, st, j) < 0) flux_log_error (h, "send state event"); done: flux_future_destroy (f); flux_kvs_txn_destroy (txn); free (key); return rc; }