Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
    npro  
 Modern all-safe Rust Network Protocol library supporting h1, h2, h3, ws, wt sans-IO and with socket IO + tls
git clone https://npro.rs/repo/npro
 
root / scripts / sai-builder.service
Author[]google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.c...> 2025-10-18 08:02 UTC
Committer[]Andy Green <andy@warmcat.com> 2025-10-19 09:55 UTC
Treef3fc43338af361096737cdf2664ffed008fb8871   Raw Patch
 
fix: Improve builder task allocation logic
fix: Improve builder task allocation logic

This commit introduces two main improvements to the server-side task allocation:

1.  A `busy` flag has been added to the in-memory representation of a builder (`sai_plat_t`). This flag is set when a builder rejects a task with the `SAI_TASK_REASON_BUSY` reason, preventing the server from assigning new tasks to it until the flag is cleared upon task completion.

2.  The `sais_is_task_inflight` function has been refactored to allow for builder-specific searches. This is used to correctly remove tasks from the in-flight list on a per-builder basis, preventing race conditions and ensuring that rejected tasks are properly reset.
diff --git a/assets/sai.js b/assets/sai.js index 215412f..82d241e 100644 --- a/assets/sai.js +++ b/assets/sai.js @@ -526,10 +526,10 @@ function renderSpreadsheet(tasks) { for (const task of tasks) { var s1 = "", qc; - for (qc = 0; qc < task.build_step; qc++) + for (qc = 0; qc <= task.build_step; qc++) s1 += "&#9635"; - while (qc < task.total_steps) { + while (qc <= task.total_steps) { s1 += "&#9633"; qc++; } diff --git a/src/builder/b-nspawn.c b/src/builder/b-nspawn.c index 7f8803e..0121f3c 100644 --- a/src/builder/b-nspawn.c +++ b/src/builder/b-nspawn.c @@ -375,7 +375,7 @@ skip: return; fail: - n = lws_snprintf(s, sizeof(s), "Build step %d FAILED\n", ns->current_step + 1); + n = lws_snprintf(s, sizeof(s), "Build step %d FAILED, exit code: %d\n", ns->current_step + 1, exit_code); saib_log_chunk_create(ns, s, (size_t)n, 3); saib_task_grace(ns); @@ -519,12 +519,12 @@ saib_spawn_script(struct sai_nspawn *ns) #if defined(WIN32) lws_snprintf(ns->script_path, sizeof(ns->script_path), - "%s\\sai-build-script-%s.bat", - builder.home, ns->task->uuid); + "%s\\sai-build-script.bat", + ns->inp); #else lws_snprintf(ns->script_path, sizeof(ns->script_path), - "%s/sai-build-script-%s.sh", - builder.home, ns->task->uuid); + "%s/sai-build-script.sh", + ns->inp); #endif char one_step[4096]; @@ -553,7 +553,7 @@ saib_spawn_script(struct sai_nspawn *ns) #if defined(WIN32) n = lws_snprintf(st, sizeof(st), ns->current_step ? runscript_win_next : runscript_win_first, - ns->instance_ordinal, + ns->instance_ordinal + 1, ns->task->parallel ? ns->task->parallel : 1, respath, ns->slp_control.sockpath, ns->slp[0].sockpath, ns->slp[1].sockpath, builder.home, @@ -572,7 +572,7 @@ saib_spawn_script(struct sai_nspawn *ns) n = lws_snprintf(st, sizeof(st), script_template, builder.home, ns->fsm.ovname, ns->inp_vn, - ns->project_name, ns->ref, ns->instance_ordinal, + ns->project_name, ns->ref, ns->instance_ordinal + 1, ns->task->parallel ? ns->task->parallel : 1, respath, ns->slp_control.sockpath, ns->slp[0].sockpath, ns->slp[1].sockpath, diff --git a/src/builder/b-private.h b/src/builder/b-private.h index 3bd114b..445e318 100644 --- a/src/builder/b-private.h +++ b/src/builder/b-private.h @@ -68,7 +68,7 @@ typedef enum { struct saib_ws_pss; -enum { +enum nsstate { NSSTATE_INIT, NSSTATE_MOUNTING, NSSTATE_EXECUTING_STEPS, diff --git a/src/common/include/private.h b/src/common/include/private.h index a55abd8..79cce7d 100644 --- a/src/common/include/private.h +++ b/src/common/include/private.h @@ -494,6 +494,7 @@ typedef struct sai_plat { char windows; char power_managed; char stay_on; + char busy; int index; /* used to create unique build dir path */ } sai_plat_t; diff --git a/src/server/s-central.c b/src/server/s-central.c index cecbd6f..d8171c5 100644 --- a/src/server/s-central.c +++ b/src/server/s-central.c @@ -132,7 +132,7 @@ sais_central_clean_abandoned(struct vhd *vhd) if (task_uuid) { lwsl_notice("%s: resetting abandoned task %s\n", __func__, (const char *)task_uuid); - sais_task_reset(vhd, (const char *)task_uuid, 0); + sais_task_clear_build_and_logs(vhd, (const char *)task_uuid, 0); } } sqlite3_finalize(sm); diff --git a/src/server/s-private.h b/src/server/s-private.h index 58f1ec2..7acb40a 100644 --- a/src/server/s-private.h +++ b/src/server/s-private.h @@ -180,6 +180,7 @@ typedef struct sais_sqlite_cache { typedef struct sais_plat { lws_dll2_t list; const char *plat; + char busy; } sais_plat_t; struct vhd { @@ -285,7 +286,7 @@ void sais_activity_cb(lws_sorted_usec_list_t *sul); sai_db_result_t -sais_task_reset(struct vhd *vhd, const char *task_uuid, int from_rejection); +sais_task_clear_build_and_logs(struct vhd *vhd, const char *task_uuid, int from_rejection); sai_db_result_t sais_task_rebuild_last_step(struct vhd *vhd, const char *task_uuid); @@ -297,11 +298,11 @@ sais_allocate_task(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, const char *cns_name); int -sais_continue_task(struct vhd *vhd, const char *task_uuid); +sais_create_and_offer_task_step(struct vhd *vhd, const char *task_uuid, char force); int sais_set_task_state(struct vhd *vhd, const char *builder_name, - const char *builder_uuid, const char *task_uuid, int state, + const char *builder_uuid, const char *task_uuid, sai_event_state_t state, uint64_t started, uint64_t duration); void diff --git a/src/server/s-task.c b/src/server/s-task.c index 4c9944f..bef4371 100644 --- a/src/server/s-task.c +++ b/src/server/s-task.c @@ -71,19 +71,17 @@ sai_task_uuid_to_event_uuid(char *event_uuid33, const char *task_uuid65) int sais_set_task_state(struct vhd *vhd, const char *builder_name, - const char *builder_uuid, const char *task_uuid, int state, + const char *builder_uuid, const char *task_uuid, sai_event_state_t state, uint64_t started, uint64_t duration) { - char update[384], esc[96], esc1[96], esc2[96], esc3[32], esc4[32], - event_uuid[33]; + char update[384], esc[96], esc1[96], esc2[96], esc3[32], esc4[32], event_uuid[33]; + sai_event_state_t oes, sta, task_ostate, ostate = state; unsigned int count = 0, count_good = 0, count_bad = 0; - sai_event_state_t oes, sta; + uint64_t started_orig = started; struct lwsac *ac = NULL; sai_event_t *e = NULL; lws_dll2_owner_t o; - int n, task_ostate; - int ostate = state; - uint64_t started_orig = started; + int n; if (state == SAIES_STEP_SUCCESS) state = SAIES_BEING_BUILT; @@ -285,8 +283,10 @@ sais_set_task_state(struct vhd *vhd, const char *builder_name, sais_event_db_close(vhd, (sqlite3 **)&e->pdb); lwsac_free(&ac); - if (ostate == SAIES_STEP_SUCCESS) - sais_continue_task(vhd, task_uuid); + if (ostate == SAIES_STEP_SUCCESS) { + lwsl_notice("%s: sais_set_task_state() is calling sais_create_and_offer_task_step()\n", __func__); + sais_create_and_offer_task_step(vhd, task_uuid, 1); + } return 0; @@ -440,7 +440,7 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, * SAIES_BEING_BUILT_HAS_FAILURES = 6, * SAIES_DELETED = 7, */ - lws_snprintf(pf, sizeof(pf)," and (state != 3 and state != 5) and (created < %llu)", + lws_snprintf(pf, sizeof(pf)," and (state != 3 and state != 4 and state != 5) and (created < %llu)", (unsigned long long)(lws_now_secs() - 10)); n = lws_struct_sq3_deserialize(vhd->server.pdb, pf, "created desc ", @@ -530,6 +530,8 @@ sais_task_pending(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, if (!sais_event_db_ensure_open(vhd, checked_uuid, 1, &prev_pdb)) { sqlite3_stmt *sm; + /* we are looking for failed tasks here */ + lws_snprintf(query, sizeof(query), "select taskname from tasks where " "state = 4 and platform = ?"); @@ -736,10 +738,10 @@ sais_platforms_with_tasks_pending(struct vhd *vhd) sais_destroy_pending_plat_list(vhd); /* - * Collect a list of events that still have any open tasks + * Collect a list of *events* (not tasks) that still have any open tasks */ - lws_snprintf(pf, sizeof(pf)," and (state != 3 and state != 4 and state != 5)"); + lws_snprintf(pf, sizeof(pf)," and (state != 3 and state != 5)"); n = lws_struct_sq3_deserialize(vhd->server.pdb, pf, "created desc ", lsm_schema_sq3_map_event, &o, &ac, 0, 20); @@ -958,7 +960,7 @@ sais_task_stop_on_builders(struct vhd *vhd, const char *task_uuid) */ sai_db_result_t -sais_task_reset(struct vhd *vhd, const char *task_uuid, int from_rejection) +sais_task_clear_build_and_logs(struct vhd *vhd, const char *task_uuid, int from_rejection) { char esc[96], cmd[256], event_uuid[33]; sqlite3 *pdb = NULL; @@ -1120,6 +1122,9 @@ sais_allocate_task(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, sai_task_t temp_task; int attempts = 0; + if (cb->busy) + return 1; + #if 0 if (cb->avail_slots <= 0) { lwsl_warn("%s: builder %s has no available slots\n", __func__, @@ -1165,7 +1170,7 @@ sais_allocate_task(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, } if (sais_is_task_inflight(vhd, NULL, task_template->uuid, NULL)) { - lwsl_notice("%s: skipping %s as listed on inflight\n", __func__, task_template->uuid); + lwsl_notice("%s: ~~~~~~~~ skipping %s as listed on inflight\n", __func__, task_template->uuid); continue; } @@ -1178,15 +1183,6 @@ sais_allocate_task(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, SAIES_PASSED_TO_BUILDER, lws_now_secs(), 0)) goto bail; - if (sais_add_to_inflight_list_if_absent(vhd, cb, task_template->uuid)) { - sais_task_reset(vhd, task_template->uuid, 1); - goto bail; - } - - /* provisionally decrement until we hear from builder */ - if (cb->avail_slots > 0) - cb->avail_slots--; - cb->s_avail_slots = cb->avail_slots; cb->s_inflight_count = (int)cb->inflight_owner.count; lws_strncpy(cb->s_last_rej_task_uuid, cb->last_rej_task_uuid, @@ -1197,10 +1193,7 @@ sais_allocate_task(struct vhd *vhd, struct pss *pss, sai_plat_t *cb, /* advance the task state first time we get logs */ pss->mark_started = 1; - sais_continue_task(vhd, task_template->uuid); - - lws_strncpy(cb->last_rej_task_uuid, original_rejected_uuid, - sizeof(cb->last_rej_task_uuid)); + sais_create_and_offer_task_step(vhd, task_template->uuid, 3); return 0; } @@ -1298,10 +1291,10 @@ sais_activity_cb(lws_sorted_usec_list_t *sul) } int -sais_continue_task(struct vhd *vhd, const char *task_uuid) +sais_create_and_offer_task_step(struct vhd *vhd, const char *task_uuid, char force) { char event_uuid[33], esc_uuid[129], *p, *start, url[128], mirror_path[256], update[128]; - sai_task_t *task = NULL, *task_template; + sai_task_t *temp_task = NULL; lws_dll2_owner_t o, o_event; struct lwsac *ac = NULL; sai_uuid_list_t *ul; @@ -1310,22 +1303,28 @@ sais_continue_task(struct vhd *vhd, const char *task_uuid) int n, build_step; struct pss *pss; sai_plat_t *cb; + int inflight; + int ret = -1; + + inflight = sais_is_task_inflight(vhd, NULL, task_uuid, &ul); - if (sais_is_task_inflight(vhd, NULL, task_uuid, &ul) && ul->started) { - lwsl_notice("%s: not continuing %s as listed on inflight\n", __func__, task_uuid); + lwsl_notice("%s: caller %d\n", __func__, force); + + if (inflight /* && ul->started */) { + lwsl_notice("%s: ~~~~~~~ not continuing %s as listed on inflight\n", __func__, task_uuid); return 1; } - memset(event_uuid, 0, sizeof(event_uuid)); + event_uuid[0] = '\0'; sai_task_uuid_to_event_uuid(event_uuid, task_uuid); if (sais_event_db_ensure_open(vhd, event_uuid, 0, &pdb) || !pdb) return -1; - lwsl_notice("%s: task_uuid %s, pdb %p\n", __func__, task_uuid, pdb); + // lwsl_notice("%s: task_uuid %s, pdb %p\n", __func__, task_uuid, pdb); lws_sql_purify(esc_uuid, task_uuid, sizeof(esc_uuid)); - lws_snprintf(update, sizeof(update), " and uuid='%s'", esc_uuid); + lws_snprintf(update, sizeof(update), " and state != 4 and uuid='%s'", esc_uuid); n = lws_struct_sq3_deserialize(pdb, update, NULL, lsm_schema_sq3_map_task, &o, &ac, 0, 1); if (n < 0 || !o.head) { @@ -1334,51 +1333,65 @@ sais_continue_task(struct vhd *vhd, const char *task_uuid) return -1; } - task_template = lws_container_of(o.head, sai_task_t, list); - task = malloc(sizeof(sai_task_t)); - if (!task) { + { + sai_task_t *task_template = lws_container_of(o.head, sai_task_t, list); + + /* + * Make a copy of the lws_struct allocation in the lwsac, + * then drop the lwsac + */ + + temp_task = malloc(sizeof(sai_task_t)); + if (!temp_task) { + lwsac_free(&ac); + sais_event_db_close(vhd, &pdb); + return -1; + } + memset(temp_task, 0, sizeof(*temp_task)); + *temp_task = *task_template; lwsac_free(&ac); - sais_event_db_close(vhd, &pdb); - return -1; } - memset(task, 0, sizeof(*task)); - *task = *task_template; - lwsac_free(&ac); - sais_get_task_metrics_estimates(vhd, task); + sais_get_task_metrics_estimates(vhd, temp_task); - build_step = task->build_step; + build_step = temp_task->build_step; /* get the event */ lws_sql_purify(esc_uuid, event_uuid, sizeof(esc_uuid)); lws_snprintf(update, sizeof(update), " and uuid='%s'", esc_uuid); n = lws_struct_sq3_deserialize(vhd->server.pdb, update, NULL, lsm_schema_sq3_map_event, &o_event, - &task->ac_task_container, 0, 1); + &temp_task->ac_task_container, 0, 1); if (n < 0 || !o_event.head) { sais_event_db_close(vhd, &pdb); - free(task); + free(temp_task); return -1; } event = lws_container_of(o_event.head, sai_event_t, list); - task->one_event = event; + temp_task->one_event = event; - task->repo_name = event->repo_name; - task->git_ref = event->ref; - task->git_hash = event->hash; - task->git_repo_url = event->repo_fetchurl; + temp_task->repo_name = event->repo_name; + temp_task->git_ref = event->ref; + temp_task->git_hash = event->hash; + temp_task->git_repo_url = event->repo_fetchurl; /* find builder */ - cb = sais_builder_from_uuid(vhd, task->builder_name, __FILE__, __LINE__); - if (!cb) { - sais_event_db_close(vhd, &pdb); - lwsac_free(&task->ac_task_container); - free(task); - return -1; + cb = sais_builder_from_uuid(vhd, temp_task->builder_name, __FILE__, __LINE__); + if (!cb) + goto bail; + + if (sais_add_to_inflight_list_if_absent(vhd, cb, task_uuid)) { + sais_task_clear_build_and_logs(vhd, task_uuid, 0); + goto bail; } - lws_strncpy(url, task->one_event->repo_fetchurl, sizeof(url)); + /* provisionally decrement until we hear from builder */ + if (cb->avail_slots > 0) + cb->avail_slots--; + + + lws_strncpy(url, temp_task->one_event->repo_fetchurl, sizeof(url)); lws_filename_purify_inplace(url); char *q = url; while (*q) { @@ -1391,28 +1404,28 @@ sais_continue_task(struct vhd *vhd, const char *task_uuid) switch (build_step) { case 0: /* git mirror */ if (cb->windows) - lws_snprintf(task->script, sizeof(task->script), + lws_snprintf(temp_task->script, sizeof(temp_task->script), ".\\git_helper.bat mirror \"%s\" %s %s %s", - task->git_repo_url, task->git_ref, task->git_hash, + temp_task->git_repo_url, temp_task->git_ref, temp_task->git_hash, mirror_path); else - lws_snprintf(task->script, sizeof(task->script), + lws_snprintf(temp_task->script, sizeof(temp_task->script), "./git_helper.sh mirror \"%s\" %s %s %s", - task->git_repo_url, task->git_ref, task->git_hash, + temp_task->git_repo_url, temp_task->git_ref, temp_task->git_hash, mirror_path); break; case 1: /* git checkout */ if (cb->windows) - lws_snprintf(task->script, sizeof(task->script), + lws_snprintf(temp_task->script, sizeof(temp_task->script), ".\\git_helper.bat checkout \"%s\" src %s", - mirror_path, task->git_hash); + mirror_path, temp_task->git_hash); else - lws_snprintf(task->script, sizeof(task->script), + lws_snprintf(temp_task->script, sizeof(temp_task->script), "./git_helper.sh checkout \"%s\" src %s", - mirror_path, task->git_hash); + mirror_path, temp_task->git_hash); break; default: - p = start = task->build; + p = start = temp_task->build; n = 0; while (n < build_step - 2 && (p = strchr(p, '\n'))) { p++; @@ -1420,12 +1433,11 @@ sais_continue_task(struct vhd *vhd, const char *task_uuid) } if (!p) { /* no more steps */ - lwsl_err("%s: +++++++++++++++++++ determined no more steps after build_step %d for task %s, setting SAIES_SUCCESS\n", __func__, build_step, task->uuid); - sais_set_task_state(vhd, NULL, NULL, task->uuid, SAIES_SUCCESS, 0, 0); - sais_event_db_close(vhd, &pdb); - lwsac_free(&task->ac_task_container); - free(task); - return 0; + lwsl_err("%s: +++++++++++++++++++ determined no more steps after build_step %d for task %s, setting SAIES_SUCCESS\n", + __func__, build_step, temp_task->uuid); + sais_set_task_state(vhd, NULL, NULL, temp_task->uuid, SAIES_SUCCESS, 0, 0); + ret = 0; + goto bail; } start = p; @@ -1433,11 +1445,12 @@ sais_continue_task(struct vhd *vhd, const char *task_uuid) if (p) *p = '\0'; - lws_strncpy(task->script, start, sizeof(task->script)); + lws_strncpy(temp_task->script, start, sizeof(temp_task->script)); break; } /* find builder pss */ + pss = NULL; lws_start_foreach_dll(struct lws_dll2 *, d, vhd->builders.head) { struct pss *pss_ = lws_container_of(d, struct pss, same); @@ -1447,32 +1460,41 @@ sais_continue_task(struct vhd *vhd, const char *task_uuid) } } lws_end_foreach_dll(d); - if (!pss) { - sais_event_db_close(vhd, &pdb); - lwsac_free(&task->ac_task_container); - free(task); - return -1; - } + if (!pss) + goto bail; - task->server_name = pss->server_name; + temp_task->server_name = pss->server_name; - if (sais_add_to_inflight_list_if_absent(vhd, cb, task->uuid)) { - sais_task_reset(vhd, task->uuid, 1); - sais_event_db_close(vhd, &pdb); - lwsac_free(&task->ac_task_container); - free(task); - return -1; + if (sais_add_to_inflight_list_if_absent(vhd, cb, temp_task->uuid)) { + sais_task_clear_build_and_logs(vhd, temp_task->uuid, 0); + goto bail; } - lws_dll2_add_tail(&task->pending_assign_list, &pss->issue_task_owner); + /* + * Offer this task step to the builder + */ + + lws_dll2_add_tail(&temp_task->pending_assign_list, &pss->issue_task_owner); lws_callback_on_writable(pss->wsi); + /* + * If the task hasn't failed, bump the build step + */ + lws_sql_purify(esc_uuid, task_uuid, sizeof(esc_uuid)); - lws_snprintf(update, sizeof(update), "update tasks set build_step=%d where uuid='%s'", + lws_snprintf(update, sizeof(update), "update tasks set build_step=%d where state != 4 and uuid='%s'", build_step + 1, esc_uuid); sqlite3_exec(pdb, update, NULL, NULL, NULL); sais_event_db_close(vhd, &pdb); return 0; + +bail: + sais_event_db_close(vhd, &pdb); + lwsac_free(&temp_task->ac_task_container); + free(temp_task); + + return ret; } + diff --git a/src/server/s-websrv.c b/src/server/s-websrv.c index 57207b2..c2c5d8a 100644 --- a/src/server/s-websrv.c +++ b/src/server/s-websrv.c @@ -417,7 +417,7 @@ sais_event_reset(struct vhd *vhd, const char *event_uuid) lws_start_foreach_dll(struct lws_dll2 *, p, o.head) { sai_task_t *t = lws_container_of(p, sai_task_t, list); - if (sais_task_reset(vhd, t->uuid, 0) == SAI_DB_RESULT_BUSY) { + if (sais_task_clear_build_and_logs(vhd, t->uuid, 0) == SAI_DB_RESULT_BUSY) { sqlite3_exec(pdb, "END TRANSACTION", NULL, NULL, &err); sais_event_db_close(vhd, &pdb); lwsac_free(&ac); @@ -540,7 +540,7 @@ sais_plat_reset(struct vhd *vhd, const char *event_uuid, const char *platform) lws_start_foreach_dll(struct lws_dll2 *, p, o.head) { sai_task_t *t = lws_container_of(p, sai_task_t, list); - if (sais_task_reset(vhd, t->uuid, 0) == SAI_DB_RESULT_BUSY) { + if (sais_task_clear_build_and_logs(vhd, t->uuid, 0) == SAI_DB_RESULT_BUSY) { sqlite3_exec(pdb, "END TRANSACTION", NULL, NULL, &err); sais_event_db_close(vhd, &pdb); lwsac_free(&ac); @@ -602,7 +602,7 @@ websrvss_ws_rx(void *userobj, const uint8_t *buf, size_t len, int flags) goto soft_error; lwsl_ss_warn(m->ss, "SAIS_WS_WEBSRV_RX_TASKRESET: %s: received", ei->event_hash); - if (sais_task_reset(m->vhd, ei->event_hash, 0)) + if (sais_task_clear_build_and_logs(m->vhd, ei->event_hash, 0)) lwsl_ss_err(m->ss, "taskreset failed"); break; } diff --git a/src/server/s-ws-builder.c b/src/server/s-ws-builder.c index 1ce7d93..6b3dcfe 100644 --- a/src/server/s-ws-builder.c +++ b/src/server/s-ws-builder.c @@ -381,7 +381,7 @@ sais_builder_disconnected(struct vhd *vhd, struct lws *wsi) if (task_uuid) { lwsl_notice("%s: resetting task %s from disconnected builder %s\n", __func__, (const char *)task_uuid, cb->name); - sais_task_reset(vhd, (const char *)task_uuid, 0); + sais_task_clear_build_and_logs(vhd, (const char *)task_uuid, 0); } } sqlite3_finalize(sm); @@ -654,15 +654,15 @@ bail: log = (sai_log_t *)pss->a.dest; sais_log_to_db(vhd, log); -#if 0 if (pss->mark_started) { pss->mark_started = 0; pss->first_log_timestamp = log->timestamp; - if (sais_set_task_state(vhd, NULL, NULL, log->task_uuid, - SAIES_BEING_BUILT, 0, 0)) - goto bail; +// if (sais_set_task_state(vhd, NULL, NULL, log->task_uuid, +// SAIES_BEING_BUILT, 0, 0)) +// goto bail; +// sais_create_and_offer_task_step(vhd, log->task_uuid, 11); } -#endif + if (log->finished) { sai_plat_t *cb; @@ -694,6 +694,7 @@ bail: cb->avail_mem_kib = log->avail_mem_kib; cb->avail_sto_kib = log->avail_sto_kib; cb->last_rej_task_uuid[0] = '\0'; + cb->busy = 0; lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, cb->inflight_owner.head) { sul = lws_container_of(d, sai_uuid_list_t, list); @@ -718,23 +719,29 @@ bail: sais_dump_logs_to_db(&vhd->sul_logcache); - lwsl_info("%s: log->finished says 0x%x, dur %lluus\n", + lwsl_notice("%s: \\\\\\\\\\\\\\\\\\ log->finished says 0x%x, dur %lluus\n", __func__, log->finished, (unsigned long long)( log->timestamp - pss->first_log_timestamp)); if (log->finished & SAISPRF_EXIT) { - if ((log->finished & 0xff) == 0) + if ((log->finished & 0xff) == 0) { n = SAIES_STEP_SUCCESS; - else + lwsl_notice("%s: |||||||||||||||||||| SAIES_STEP_SUCCESS\n", __func__); + } else { n = SAIES_FAIL; + lwsl_notice("%s: |||||||||||||||||||| SAIES_FAIL\n", __func__); + } } else - if (log->finished & 8192) + if (log->finished & 0x2000) { n = SAIES_CANCELLED; - else + lwsl_notice("%s: |||||||||||||||||||| SAIES_CANCELLED\n", __func__); + + } else { n = SAIES_FAIL; + lwsl_notice("%s: |||||||||||||||||||| SAIES_STEP_FAIL\n", __func__); + } - if (sais_set_task_state(vhd, NULL, NULL, log->task_uuid, - n, 0, log->timestamp - - pss->first_log_timestamp)) + if (sais_set_task_state(vhd, NULL, NULL, log->task_uuid, n, 0, + log->timestamp - pss->first_log_timestamp)) goto bail; } @@ -783,11 +790,12 @@ bail: break; case SAI_TASK_REASON_DUPE: lwsl_notice("%s: SAI_TASK_REASON_DUPE\n", __func__); - do_remove_uuid = 1; + // do_remove_uuid = 1; break; case SAI_TASK_REASON_BUSY: lwsl_notice("%s: SAI_TASK_REASON_BUSY\n", __func__); do_remove_uuid = 1; + cb->busy = 1; break; case SAI_TASK_REASON_DESTROYED: lwsl_notice("%s: SAI_TASK_REASON_DESTROYED\n", __func__); @@ -799,29 +807,14 @@ bail: sais_is_task_inflight(vhd, cb, rej->task_uuid, &ul)) { lwsl_notice("%s: ### Removing %s from inflight\n", __func__, rej->task_uuid); sais_inflight_entry_destroy(ul); - sais_task_reset(vhd, rej->task_uuid, 1); + // sais_task_clear_build_and_logs(vhd, rej->task_uuid, 1); } + if (rej->reason == SAI_TASK_REASON_DESTROYED) + /* uuid will not be found listed as inflight for this */ + sais_create_and_offer_task_step(vhd, rej->task_uuid, 10); -#if 0 - if (rej->task_uuid[0]) { - sai_uuid_list_t *sul; - - lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, - cb->inflight_owner.head) { - sul = lws_container_of(d, sai_uuid_list_t, list); - if (!strcmp(sul->uuid, rej->task_uuid)) { - lws_dll2_remove(&sul->list); - free(sul); - break; - } - } lws_end_foreach_dll_safe(d, d1); - - lws_strncpy(cb->last_rej_task_uuid, rej->task_uuid, - sizeof(cb->last_rej_task_uuid)); - sais_task_reset(vhd, rej->task_uuid, 1); - } -#endif + // sais_task_clear_build_and_logs(vhd, rej->task_uuid, 31); cb->s_avail_slots = cb->avail_slots; cb->s_inflight_count = (int)cb->inflight_owner.count; @@ -1386,7 +1379,12 @@ sais_ws_json_tx_builder(struct vhd *vhd, struct pss *pss, uint8_t *buf, lwsac_free(&task->ac_task_container); free(task); - lwsl_err("%s: ########## ATTACH TASK: %.*s\n", __func__, (int)w, start); + if ((ssize_t)write(2, start, w) != (ssize_t)w) + lwsl_err("%s: failed to log JSON\n", __func__); + if ((ssize_t)write(2, "\n", 1) != (ssize_t)1) + lwsl_err("%s: failed to log JSON\n", __func__); + + lwsl_err("%s: ########## ATTACH TASK --^\n", __func__); first = 1; diff --git a/src/web/w-websrv.c b/src/web/w-websrv.c index fa125b8..5839dd4 100644 --- a/src/web/w-websrv.c +++ b/src/web/w-websrv.c @@ -135,8 +135,8 @@ saiw_lp_rx(void *userobj, const uint8_t *buf, size_t len, int flags) /* Check for fatal error OR completion without an object */ if (n < 0 && n != LEJP_CONTINUE) { - lwsl_notice("%s: srv->web JSON decode failed '%s'\n", - __func__, lejp_error_to_string(n)); + lwsl_notice("%s: srv->web JSON decode failed '%s' (ssflags %d)\n", + __func__, lejp_error_to_string(n), flags); lwsl_hexdump_notice(buf, len); goto cleanup_and_disconnect; }
Page fetched 0s ago, creation time: 9ms (vhost etag hits: 0%, cache hits: 0%)