Skip to content

Latest commit

 

History

History

cron

Folders and files

README.md

HAIP scheduled jobs (cron)

HAIP has no in-process scheduler. Run these scripts from system cron, Kubernetes CronJob, or similar.

Full endpoint reference: docs/operations/cron.md.

Authentication

All endpoints require a Keycloak JWT with the appropriate realm role (night_auditor or admin for night audit; admin, night_auditor, or revenue_manager for group cutoffs).

Two supported options:

Option A — Client credentials (recommended)

  1. In Keycloak, create a confidential client (e.g. haip-cron) with Service accounts enabled.
  2. Assign realm roles to the service account user: at minimum night_auditor (or admin).
  3. Copy the client secret from the Credentials tab.
  4. Export:
export HAIP_URL=https://pms.example.com
export HAIP_PROPERTY_ID=<property-uuid>
export KEYCLOAK_URL=https://auth.example.com
export KEYCLOAK_REALM=haip
export KEYCLOAK_CLIENT_ID=haip-cron
export KEYCLOAK_CLIENT_SECRET=<secret>

Scripts fetch a short-lived token automatically before each run.

Full Keycloak + local user linking guide: docs/integrations/service-principal.md.

Option B — Pre-issued token

If you refresh tokens externally, set HAIP_CRON_TOKEN to a valid Bearer JWT and omit Keycloak client vars.

Environment variables

Variable Required Description
HAIP_URL yes Base URL of your deployment (no trailing slash)
HAIP_PROPERTY_ID yes Property UUID to operate on
HAIP_BUSINESS_DATE no Night audit date (YYYY-MM-DD); defaults to yesterday UTC
HAIP_CRON_TOKEN option B Pre-fetched JWT
KEYCLOAK_URL option A Keycloak base URL
KEYCLOAK_REALM option A Realm name (default haip)
KEYCLOAK_CLIENT_ID option A Cron service client id
KEYCLOAK_CLIENT_SECRET option A Cron service client secret
OIDC_TOKEN_URL option A, non-Keycloak IdP Token endpoint of any OIDC provider (e.g. Zitadel <issuer>/oauth/v2/token); replaces KEYCLOAK_URL + KEYCLOAK_REALM
OIDC_TOKEN_SCOPE optional scope sent with the client-credentials grant (Zitadel needs the project audience scope)

Install

chmod +x scripts/cron/*.sh

Copy crontab.example, edit paths and env, then:

crontab scripts/cron/crontab.example

Or source env from a file:

# /etc/haip/cron.env  (mode 600, root-owned)
set -a
source /etc/haip/cron.env
set +a
/path/to/haip/scripts/cron/night-audit.sh

Scripts

Script Schedule (typical) API
night-audit.sh Daily ~00:30 property local time POST /api/v1/night-audit/run with "mode": "unattended"
group-cutoffs.sh Daily after night audit POST /api/v1/groups/blocks/process-cutoffs
agent-runs.sh <agentType> See matrix in docs/operations/cron.md POST /api/v1/agents/:propertyId/:agentType/run?triggeredBy=schedule

night-audit.sh posts {"propertyId","businessDate","mode":"unattended"}. That marks the run as a scheduled close. Do not drop mode when reimplementing the call. A body without mode is a manual close. The staff Night Audit screen omits mode on purpose. An API that accepts the extra field and does not use it ignores it and closes as before.

Revenue cadence: cron revenue_manager only — do not also schedule demand_forecast / pricing / overbooking / channel_mix / group_pickup (they run inside RManager).

Scripts exit non-zero on HTTP errors (non-2xx). Role: admin.