Mercurial > sci
changeset 57:bc617784ec97
scid: many fixes in pages
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 17 Aug 2022 18:26:27 +0200 |
parents | 308aa1086702 |
children | 7a4112eec15b |
files | scid/page-index.c scid/page-workers.c scid/theme.h themes/bulma/theme.js themes/bulma/worker.mustache |
diffstat | 5 files changed, 52 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/scid/page-index.c Wed Aug 17 12:51:04 2022 +0200 +++ b/scid/page-index.c Wed Aug 17 18:26:27 2022 +0200 @@ -26,28 +26,24 @@ #include "util.h" static void -set_job_status(json_t *project, json_t *job, json_t *jobresults) +set_job_status(json_t *project, json_t *job, json_t *jobresults, size_t *ns, size_t *nf) { - json_t *iter; + json_t *iter, *status; int exitcode, sigcode; - size_t i, ns = 0, nf = 0; + size_t i; /* Compute number of failures and number of success. */ json_array_foreach(jobresults, i, iter) { json_unpack(iter, "{si si}", "exitcode", &exitcode, "sigcode", &sigcode); if (exitcode == 0 && sigcode == 0) - ns++; + (*ns)++; else - nf++; - - /* Also add exitcode and sigcode to the job object. */ - json_object_set_new(job, "exitcode", json_integer(exitcode)); - json_object_set_new(job, "sigcode", json_integer(sigcode)); + (*nf)++; } - json_object_set_new(project, "n-failed", json_integer(nf)); - json_object_set_new(project, "n-success", json_integer(ns)); + /* At least one failed, set status to false. */ + json_object_set_new(job, "status", json_boolean(nf)); } static void @@ -55,7 +51,7 @@ { json_t *iter, *jobresults; json_int_t job_id; - size_t i; + size_t i, ns = 0, nf = 0; json_array_foreach(jobs, i, iter) { /* Don't populate too much. */ @@ -74,11 +70,13 @@ if (!(jobresults = db_jobresult_list_by_job_group(job_id))) continue; - set_job_status(project, iter, jobresults); + set_job_status(project, iter, jobresults, &ns, &nf); json_decref(jobresults); } json_object_set_new(project, "jobs", jobs); + json_object_set_new(project, "n-failed", json_integer(nf)); + json_object_set_new(project, "n-success", json_integer(ns)); } /*
--- a/scid/page-workers.c Wed Aug 17 12:51:04 2022 +0200 +++ b/scid/page-workers.c Wed Aug 17 18:26:27 2022 +0200 @@ -29,15 +29,15 @@ static void get_one(struct kreq *r) { - json_t *worker, *jobs; + json_t *worker, *jobresults; char *body; if (!(worker = db_worker_find(r->path))) pageutil_status(r, KHTTP_404); else { /* Silently ignore jobs if it has failed. */ - if ((jobs = db_jobresult_list_by_worker(r->path))) - json_object_set_new(worker, "jobs", jobs); + if ((jobresults = db_jobresult_list_by_worker(r->path))) + json_object_set_new(worker, "jobresults", jobresults); body = theme_render("onPageWorker", worker); pageutil_render(r, KHTTP_200, KMIME_TEXT_HTML, body);
--- a/scid/theme.h Wed Aug 17 12:51:04 2022 +0200 +++ b/scid/theme.h Wed Aug 17 18:26:27 2022 +0200 @@ -56,8 +56,7 @@ * "jobs": [ * { * "job": job-id, - * "tag": "job tag / revision", - * "status": "failed / success" // failed if at least one has failed + * "tag": "job tag / revision" * } * ] * "n-failed": number of failed jobs @@ -97,6 +96,28 @@ * } * ``` * + * #### onPageWorker + * + * Called to show a worker information and its recent jobs. + * + * ```javascript + * { + * "name": "worker name", + * "desc": "worker description", + * "jobresults": [ + * { + * "id": jobresult id, + * "job_id": parent job id, + * "worker_name": "worker which realized the task", + * "console": "stdout and stderr merge", + * "exitcode": process exit code, + * "sigcode": process termination code (0 means success), + * "date": job result insertion date + * } + * ] + * } + * ``` + * * [mustache]: https://mustache.github.io/ */
--- a/themes/bulma/theme.js Wed Aug 17 12:51:04 2022 +0200 +++ b/themes/bulma/theme.js Wed Aug 17 18:26:27 2022 +0200 @@ -26,10 +26,20 @@ Scid.render(rdr, "footer.mustache"); } +function isFailed(job) +{ + /* Can be failed if there is a property status to false. */ + if (typeof (job.status) === "boolean") + return job.status === false; + + /* Otherwise, check for exitcode/sigcode that must be present. */ + return job.exitcode !== 0 || job.sigcode !== 0; +} + function addStatusClasses(jobs) { for (var j = 0; j < jobs.length; ++j) { - if (jobs[j].exitcode !== 0 || jobs[j].sigcode !== 0) { + if (isFailed(jobs[j])) { jobs[j].color = "is-danger"; jobs[j].textcolor = "has-text-danger"; jobs[j].status = "failed"; @@ -70,9 +80,8 @@ function onPageWorker(rdr, data) { /* Similar to index page, add classes. */ - Scid.print(JSON.stringify(data, null, 4)); - if (typeof (data.jobs) === "object") - addStatusClasses(data.jobs); + if (typeof (data.jobresults) === "object") + addStatusClasses(data.jobresults); render(rdr, "worker.mustache", "sci -- worker", data); }
--- a/themes/bulma/worker.mustache Wed Aug 17 12:51:04 2022 +0200 +++ b/themes/bulma/worker.mustache Wed Aug 17 18:26:27 2022 +0200 @@ -25,10 +25,10 @@ <th>status</th> </tr> </thead> - {{#jobs}} + {{#jobresults}} <tr> <td><a href="/jobresults/{{id}}">{{id}}</a></td> <td><span class="tag {{textcolor}} is-light">{{status}}</span></td> </tr> - {{/jobs}} + {{/jobresults}} </table>