A new member could end up with a Loomio account and a Matrix account and see NOTHING: no forum group, no Space. Three defects: * sync_matrix_space() gated each member on the SPACE's membership, so an account already joined/invited to the Space was skipped for EVERY room. A member whose invite pass was interrupted (or who predates a room added to MATRIX_INVITE_ROOMS later) never received that room — and a restricted child room is invisible until you are invited to it. The gate is now per room, from a single up-front membership snapshot; a room whose membership cannot be read is left alone rather than invited into blindly. * a 429 slept for retry_after_ms (minutes) INSIDE the pass, so a scheduled run could outlive its own tick. A rate limit now ENDS the pass; the next run resumes (every invite is idempotent). * a member sitting in the Loomio group with no loomio_invited_at stamp reads as 'never invited' — the dedupe guard was only as good as the rows it had. The sync now heals the record from the live roster. And the activation window itself: provisioning skips an unactivated account by design, and activation happens later with nobody watching, so the 3x/day sweep was the pickup. New /admin/service-sync + a 5-minute scheduler task fires the same idempotent syncs while any member still awaits an invite (one SELECT when none do), and deliberately is NOT /admin/sweep — it never touches Open Collective, allowance logic or member mail. tests/test_service_invites.py proves the per-room gate, resumable rate limits, the unreadable-room skip, the record heal and the endpoint's idle/run paths.
50 lines
1.9 KiB
Bash
50 lines
1.9 KiB
Bash
#!/bin/sh
|
|
# Frequent service-invite sync — run by the Cloudron scheduler addon every
|
|
# few minutes.
|
|
#
|
|
# WHY: a new member is provisioned with an UNACTIVATED Cloudron account, and
|
|
# the Loomio/Matrix syncs deliberately skip an unactivated account (never
|
|
# invite a half-created one). The member activates later, by following the
|
|
# setup link in their welcome email — and until this job existed, the next
|
|
# thing to look at them was the 3x/day membership sweep, so a brand-new member
|
|
# could sit without forum or Space access for hours.
|
|
#
|
|
# Calls the portal's own /admin/service-sync endpoint (localhost), which fires
|
|
# the same idempotent Loomio + Matrix syncs the sweep runs, but ONLY while some
|
|
# member is still awaiting their invites (one SELECT when nobody is).
|
|
#
|
|
# The ADMIN_TOKEN env var is shared with the main app (the scheduler runs in
|
|
# the same launch environment), so we use it to authenticate. Admin auth is a
|
|
# header, never a URL token.
|
|
#
|
|
# Deliberately NOT the full /admin/sweep: that reconciles against Open
|
|
# Collective, runs allowance logic and can send member mail. This job must only
|
|
# ever send the invites a member is owed.
|
|
|
|
set -e
|
|
|
|
if [ -z "$ADMIN_TOKEN" ]; then
|
|
echo "service-sync: ADMIN_TOKEN is not set; aborting" >&2
|
|
exit 1
|
|
fi
|
|
|
|
python3 - "$ADMIN_TOKEN" <<'PY'
|
|
import sys, urllib.request, urllib.error
|
|
|
|
token = sys.argv[1]
|
|
url = "http://127.0.0.1:8000/admin/service-sync"
|
|
req = urllib.request.Request(url, method="POST", data=b"", headers={
|
|
"Content-Type": "application/json",
|
|
"X-Admin-Token": token,
|
|
})
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=300) as resp:
|
|
print("service-sync:", resp.read().decode())
|
|
except urllib.error.HTTPError as e:
|
|
print(f"service-sync: HTTP {e.code}: {e.read().decode()}", file=sys.stderr)
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"service-sync: request failed: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
PY
|