2 Commits
Author SHA1 Message Date
grabowski 62a37b677a Anchor: each run ends its transaction itself
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Successful in 1m18s
CI / release (push) Skipped
A run that was not due dropped its transaction, and sqlx rolls a dropped
one back only when the connection is returned, from a background task.
Until then the advisory lock stays taken, so a run right after it (the
test's next call on a busy CI runner; on the server a tick that comes at
the wrong moment) found the lock taken and skipped. Every way out of
run_daily now rolls back explicitly (sending happens on the pool; the
transaction only holds the lock). The test checks from a connection of
its own that no lock is left after a run that sent nothing.
2026-11-23 00:31:51 +07:00
grabowski 4dba0475c7 Docs: releases arrive by webhook
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Failing after 51s
CI / release (push) Skipped
B4L/visa's release webhook (hook 6) starts cnx01's fetch at once, through
the fleet's hooks.cnx.network (cnx-network-clan PR #168); the 15-minute
timer stays as the backstop.
2026-11-23 00:19:31 +07:00
4 changed files with 27 additions and 8 deletions

No files matched your search

+4 -3
View File
@@ -200,9 +200,10 @@ A push to `main` is a release, as for thukthuk and lampbench-web: once the
checks pass, CI builds the server on Ubuntu 22.04, signs it with a key only checks pass, CI builds the server on Ubuntu 22.04, signs it with a key only
CI holds (the repository secret `RELEASE_SIGNING_KEY`; its public half is CI holds (the repository secret `RELEASE_SIGNING_KEY`; its public half is
`release/allowed-signers`) and publishes it as the next release, named by `release/allowed-signers`) and publishes it as the next release, named by
date (2026.11.0, 2026.11.1, ...). cnx01 looks every 15 minutes, installs a date (2026.11.0, 2026.11.1, ...). The release's webhook tells cnx01 at once
release only with that signature, and restarts the app on it; migrations (the fleet's `hooks.cnx.network/hooks/visa-release`), and it also looks
run at that start. So `main` must stay deployable. On cnx01, every 15 minutes; it installs a release only with that signature, and
restarts the app on it; migrations run at that start. So `main` must stay deployable. On cnx01,
`visa-releases status` shows what runs, and `visa-releases rollback` goes `visa-releases status` shows what runs, and `visa-releases rollback` goes
back one release and holds it until `visa-releases unpin`; a rollback does back one release and holds it until `visa-releases unpin`; a rollback does
not undo a migration. The fleet's VM test `checks.visa` signs in through a not undo a migration. The fleet's VM test `checks.visa` signs in through a
+1 -1
View File
@@ -42,7 +42,7 @@ The first round of questions was answered on November 17, 2026.
| Question | Decision | | Question | Decision |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Where it runs | cnx01, installed on the host like proplan and lampbench: database `visa` on cnx01's PostgreSQL, documents in its Garage, encrypted by the app, borg backups to juliet | | Where it runs | cnx01, installed on the host like proplan and lampbench: database `visa` on cnx01's PostgreSQL, documents in its Garage, encrypted by the app, borg backups to juliet |
| Releases (Nov 20) | as thukthuk and lampbench-web: every push to main that passes CI becomes a signed release (CalVer), which cnx01 fetches and restarts on within 15 minutes; no fleet PR per release | | Releases (Nov 20) | as thukthuk and lampbench-web: every push to main that passes CI becomes a signed release (CalVer), which cnx01 fetches and restarts on at once (the release webhook, since Nov 23; the 15-minute timer as backstop); no fleet PR per release |
| Documents in Garage | bucket `visa-documents` on cnx01's Garage, 10 GB (Nov 19, 2026); the app encrypts each file before it leaves the app, so Garage holds no key; Garage's SSE-C is off | | Documents in Garage | bucket `visa-documents` on cnx01's Garage, 10 GB (Nov 19, 2026); the app encrypts each file before it leaves the app, so Garage holds no key; Garage's SSE-C is off |
| How it is published | bkk01 publishes `app.lannadesk.com` through a `modules/web-sites` app entry; `visa.buildfor.life` and the app's paths on `lannadesk.com` redirect there | | How it is published | bkk01 publishes `app.lannadesk.com` through a `modules/web-sites` app entry; `visa.buildfor.life` and the app's paths on `lannadesk.com` redirect there |
| Login | Kanidm at id.cnx.network, OAuth2 client `visa-web`, group `visa` with grabowski and oltmanns | | Login | Kanidm at id.cnx.network, OAuth2 client `visa-web`, group `visa` with grabowski and oltmanns |
+9 -4
View File
@@ -319,12 +319,16 @@ pub async fn run_daily(cfg: &Config, db: &PgPool, now: DateTime<Utc>) -> Result<
if cfg.mail.is_none() { if cfg.mail.is_none() {
return Ok(None); return Ok(None);
} }
// one server sends: the lock keeps two runs from both sending // one server sends: the lock keeps two runs from both sending. Every
// way out ends the transaction itself: a dropped one is only rolled
// back when its connection is used again, and until then it keeps the
// lock, so the next run would find it taken and skip the day.
let mut tx = db.begin().await?; let mut tx = db.begin().await?;
let locked: bool = sqlx::query_scalar("SELECT pg_try_advisory_xact_lock(7464530001)") let locked: bool = sqlx::query_scalar("SELECT pg_try_advisory_xact_lock(7464530001)")
.fetch_one(&mut *tx) .fetch_one(&mut *tx)
.await?; .await?;
if !locked { if !locked {
tx.rollback().await?;
return Ok(None); return Ok(None);
} }
let today = now.with_timezone(&dates::bangkok()).date_naive(); let today = now.with_timezone(&dates::bangkok()).date_naive();
@@ -334,11 +338,12 @@ pub async fn run_daily(cfg: &Config, db: &PgPool, now: DateTime<Utc>) -> Result<
.fetch_all(db) .fetch_all(db)
.await?; .await?;
if !due(now, &rows) { if !due(now, &rows) {
tx.rollback().await?;
return Ok(None); return Ok(None);
} }
let out = send(cfg, db, true, "daily anchor", now).await?; let out = send(cfg, db, true, "daily anchor", now).await;
tx.commit().await?; tx.rollback().await?;
Ok(Some(out)) Ok(Some(out?))
} }
/// Checks every ten minutes whether the day's anchor is due. /// Checks every ten minutes whether the day's anchor is due.
+13
View File
@@ -289,6 +289,19 @@ async fn the_journal_anchor_goes_out_daily_and_checks_later(pool: PgPool) {
.unwrap() .unwrap()
.is_none() .is_none()
); );
// a run that sends nothing lets go of its lock before it returns, as a
// connection of its own (another run's) sees it
let mut other = <sqlx::PgConnection as sqlx::Connection>::connect_with(&pool.connect_options())
.await
.unwrap();
let held: i64 = sqlx::query_scalar(
"SELECT count(*) FROM pg_locks WHERE locktype = 'advisory' \
AND database = (SELECT oid FROM pg_database WHERE datname = current_database())",
)
.fetch_one(&mut other)
.await
.unwrap();
assert_eq!(held, 0, "the anchor's lock is still held");
let out = visa::anchor::run_daily(&cfg, &pool, cm(0, 7, 5)) let out = visa::anchor::run_daily(&cfg, &pool, cm(0, 7, 5))
.await .await
.unwrap(); .unwrap();