Skip to content

Commit

Permalink
job-list: split up R parsing function
Browse files Browse the repository at this point in the history
Problem: In the near future, R may be updated and may need to be
parsed multiple times.  R parsing code sits in a function that is called
only when R is initially loaded.

Split R parsing into two functions, one for loading R and one for
parsing R.  That way parsing R can be done multiple times without the
additional call to json_loads().
  • Loading branch information
chu11 authored and grondo committed Oct 26, 2023
1 parent f5c34b7 commit 47e83de
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/modules/job-list/job_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,20 @@ int job_parse_jobspec_fatal (struct job *job, const char *s, json_t *updates)
return job_jobspec_update (job, updates);
}

static int parse_R (struct job *job, const char *s, bool allow_nonfatal)
static int load_R (struct job *job, const char *s, bool allow_nonfatal)
{
json_error_t error;

if (!(job->R = json_loads (s, 0, &error))) {
flux_log (job->h, LOG_ERR,
"%s: job %s invalid R: %s",
__FUNCTION__, idf58 (job->id), error.text);
return allow_nonfatal ? 0 : -1;
}
return 0;
}

static int parse_R (struct job *job, bool allow_nonfatal)
{
struct rlist *rl = NULL;
struct idset *idset = NULL;
Expand All @@ -396,13 +409,6 @@ static int parse_R (struct job *job, const char *s, bool allow_nonfatal)
struct rnode *rnode;
int saved_errno, rc = -1;

if (!(job->R = json_loads (s, 0, &error))) {
flux_log (job->h, LOG_ERR,
"%s: job %s invalid R: %s",
__FUNCTION__, idf58 (job->id), error.text);
goto nonfatal_error;
}

if (!(rl = rlist_from_json (job->R, &error))) {
flux_log_error (job->h, "rlist_from_json: %s", error.text);
goto nonfatal_error;
Expand Down Expand Up @@ -456,12 +462,16 @@ static int parse_R (struct job *job, const char *s, bool allow_nonfatal)

int job_parse_R (struct job *job, const char *s)
{
return parse_R (job, s, true);
if (load_R (job, s, true) < 0)
return -1;
return parse_R (job, true);
}

int job_parse_R_fatal (struct job *job, const char *s)
{
return parse_R (job, s, false);
if (load_R (job, s, false) < 0)
return -1;
return parse_R (job, false);
}

int job_jobspec_update (struct job *job, json_t *updates)
Expand Down

0 comments on commit 47e83de

Please sign in to comment.