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 / src / power / p-ws-server.c
Author[]Andy Green <andy@warmcat.com> 2021-01-02 16:08 UTC
Committer[]Andy Green <andy@warmcat.com> 2021-01-03 07:48 UTC
Treec0e388431e832424a2caddb6914159b34eae6b48   Raw Patch
 
server: delay notification build for 5s after end of POST
server: delay notification build for 5s after end of POST

gitolite / git server seems to be in a race between the hook POST and
the refs being available from the server.

Delay handing out any tasks from a notification until 5-6s later
diff --git a/src/builder/b-sai.c b/src/builder/b-sai.c index 839211d..b42a031 100644 --- a/src/builder/b-sai.c +++ b/src/builder/b-sai.c @@ -62,8 +62,8 @@ static const char * const default_ss_policy = "]," "\"conceal\":" "99999," "\"jitterpc\":" "20," - "\"svalidping\":" "300," - "\"svalidhup\":" "350" + "\"svalidping\":" "100," + "\"svalidhup\":" "110" "}}" "]," @@ -75,7 +75,7 @@ static const char * const default_ss_policy = "\"s\": [" /* - * The main connection to a server carrying events and logs + * The main connection to sai-server */ "{\"sai_builder\": {" "\"endpoint\":" "\"${url}\"," @@ -83,6 +83,7 @@ static const char * const default_ss_policy = "\"protocol\":" "\"ws\"," "\"ws_subprotocol\":" "\"com-warmcat-sai\"," "\"http_url\":" "\"\"," /* filled in by url */ + "\"nailed_up\":" "true," "\"tls\":" "true," "\"retry\":" "\"default\"," "\"metadata\": [" diff --git a/src/common/include/private.h b/src/common/include/private.h index dfb6c43..22bfbc6 100644 --- a/src/common/include/private.h +++ b/src/common/include/private.h @@ -41,6 +41,8 @@ typedef enum { SAIES_CANCELLED = 5, SAIES_BEING_BUILT_HAS_FAILURES = 6, SAIES_DELETED = 7, + + SAIES_NOT_READY_FOR_BUILD = 8, } sai_event_state_t; enum { diff --git a/src/server/s-central.c b/src/server/s-central.c index 5af8b8d..8d790ae 100644 --- a/src/server/s-central.c +++ b/src/server/s-central.c @@ -94,7 +94,26 @@ sais_central_clean_abandoned(struct vhd *vhd) char *err = NULL; /* - * Such tasks should go into CANCELLED + * Check for tasks that have waited long enough since + * the notification to allow to be built + */ + + lws_snprintf(s, sizeof(s), + "update tasks set state=0 where " + "(state=%u) and last_updated < %llu", + SAIES_NOT_READY_FOR_BUILD, (unsigned long long) + (lws_now_secs() - 5)); + + if (sqlite3_exec(pdb, s, NULL, NULL, &err) != + SQLITE_OK) { + lwsl_err("%s: %s: %s: fail\n", __func__, s, + sqlite3_errmsg(pdb)); + if (err) + sqlite3_free(err); + } + + /* + * Check for tasks that should go into CANCELLED */ lws_snprintf(s, sizeof(s), diff --git a/src/server/s-comms.c b/src/server/s-comms.c index 80a45b4..e4727f1 100644 --- a/src/server/s-comms.c +++ b/src/server/s-comms.c @@ -410,12 +410,14 @@ callback_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user, pss->vhd = vhd; - for (n = 0; n < (int)LWS_ARRAY_SIZE(well_known); n++) - if (!strncmp((const char *)in, well_known[n], - strlen(well_known[n]))) { + for (n = 0; n < (int)LWS_ARRAY_SIZE(well_known); n++) { + + size_t q = strlen(in), t = strlen(well_known[n]); + if (q >= t && !strcmp((const char *)in + q - t, well_known[n])) { mu = n; break; } + } pss->our_form = 0; diff --git a/src/server/s-notification.c b/src/server/s-notification.c index d401758..45f3d52 100644 --- a/src/server/s-notification.c +++ b/src/server/s-notification.c @@ -224,6 +224,15 @@ sai_tuple_compare(const char *req, size_t req_len, const char *plat) /* * We parse the saifile JSON + * + * The backdrop of this is the remote's hook that's letting us know all this + * won't update his refs to the push described here until he's finished + * uploading the saifile POST. + * + * So although we are going to add the tasks as we parse them, in fact we + * can't hand any of them out to builders until a short time after we got to + * the end of the POST, otherwise the builders are not going to find the + * right refs in the repo yet. */ static signed char @@ -523,7 +532,7 @@ sai_saifile_lejp_cb(struct lejp_ctx *ctx, char reason) pss->sn.e.repo_fetchurl; pss->sn.e.last_updated = (unsigned long long)lws_now_secs(); - pss->sn.e.state = 0; + pss->sn.e.state = SAIES_WAITING; lws_strncpy(pss->sn.t.platform, pl->name, sizeof(pss->sn.t.platform)); @@ -965,11 +974,14 @@ sai_notification_file_upload_cb(void *data, const char *name, lwsl_notice("%s: notification inserted into db\n", __func__); /* - * Reassess now if there's a builder we can match to a pending task + * The tasks are all in there but set to state + * NOT_READY_FOR_BUILD, the periodic central scan + * switch them over to WAITING when they have been like that + * for 2s */ lws_sul_schedule(pss->vhd->context, 0, &pss->vhd->sul_central, - sais_central_cb, 1); + sais_central_cb, 1 * LWS_US_PER_SEC); return 0; diff --git a/src/server/s-task.c b/src/server/s-task.c index f80d8da..6149701 100644 --- a/src/server/s-task.c +++ b/src/server/s-task.c @@ -263,7 +263,7 @@ static const sai_task_t * sais_task_pending(struct vhd *vhd, struct lwsac **pac, const char *platform) { struct lwsac *ac = NULL; - char esc[96], pf[96]; + char esc[96], pf[128]; lws_dll2_owner_t o; int n; @@ -279,10 +279,11 @@ sais_task_pending(struct vhd *vhd, struct lwsac **pac, const char *platform) * scope whether we find something or not */ - n = lws_struct_sq3_deserialize(vhd->server.pdb, - " and (state != 3 and state != 4 and state != 5)", - "created desc ", lsm_schema_sq3_map_event, &o, - &ac, 0, 10); + 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 ", + lsm_schema_sq3_map_event, &o, &ac, 0, 10); if (n < 0 || !o.head) { // lwsl_notice("%s: all events complete\n", __func__); /* error, or there are no events that aren't complete */
Page fetched 0s ago, creation time: 4ms (vhost etag hits: 0%, cache hits: 0%)