Skip to main content

The asynchronous pipeline

Long work runs in five workers on the contract queue. In deployed environments the transport is Upstash QStash; every message is also recorded in the queue ledger (queue_event), so a failed job is retried, traced and never lost. Handlers live in backend/horizon-api/lib/queue/contract/handlers/. A platform cron (/api/v3/cron/queue/event/reconcile, every 10 minutes) requeues open jobs (received, enqueued or processing) that have stalled.

Manual review

With company_phase = last (used by the seeded workflows), every contract signed by its customers waits in pending_review until Maihue operations decide. The customer is already in the customer portal by then.
  • approve is accepted only from pending_review. It moves the contract to awaiting_enterprise_signature and enqueues the enterprise worker.
  • reject needs a reason and is accepted from pending_review or awaiting_enterprise_signature. It cancels the signature group and the contract.

Recovery tools

A signature counts as stuck when it has waited more than 30 minutes on the enterprise phase: a signature group in awaiting_enterprise_signature (with company_phase = last the group reaches that status as soon as the customers sign, so a contract still waiting for review also shows up), a company_phase = first group whose enterprise turn is incomplete, or a sealed group whose contract is still in pending_signature, in_signature, partially_signed or awaiting_enterprise_signature.

Monitoring

Better Stack watches the flow; its configuration lives in infra/betterstack/ and is described in Monitoring — Terraform. The stuck scan runs as a cron (/api/v3/cron/signature/enterprise-stuck, every 10 minutes in production). It reports; the retry above is a manual decision. Incident handling follows the Monitoring runbook.

Running the flow locally

Start the apps with Turbo:
Notes for an end-to-end run:
  • Mock mode seals for Maihue a few seconds after the customer signs, so the wizard can be walked to the password. To rehearse the review, open the wizard with ?mock_enterprise_seal=pending (also slow or never) once the magic link was exchanged; auto is the default. After the mock checkout the portal calls the mock POST …/payment/enrollment-notify until the card is attached.
  • Real mode needs the platform signing certificates configured locally (see backend/horizon-api/.env.example) for the countersignature to seal. Approve the review with a back-office token as shown above.
  • Fintoc webhooks cannot reach localhost. Against a local API, the portal calls POST …/payment/enrollment-notify after returning from Fintoc so other open tabs still see the new method; deployed environments answer 404 to that route.

Internal runbooks

Step-by-step runbooks live in the repository under docs/operations/:

Code