matchGrants (nightly 05:15): per candidate org (NH + good standing + primary ICP) ensure a v0 NTEE-derived profile embedding (RETRIEVAL_QUERY, confidence 0.2 stub the Stage 4 profiler upgrades in place), retrieve top-50 open grants by pgvector cosine with SQL-enforced cheap gates (deadline >=21d, ceiling >=10K), run entity/geography gates in TS, score deterministically, upsert pair-keyed matches, reassign hero. Scoring: pure scoreMatch (mission fit 30 / capacity 15 / competition 15 / effort 10 / runway 5; precedent's 25 reserved until the 990-PF index; easy win >= 50/75). Eligibility gate now pattern-matches Grants.gov applicantTypes prose, conservatively (ambiguous entries do not admit). application_form_supported ignored for pass/fail per the manual-first decision, still recorded in rationale. Schema: unique (org_id, grant_id) on matches; unique org_id on org_profiles (latest-profile semantics). Review queue query now ordered hero > easy-win > score and capped at 100. Live run: 64 orgs -> 3,200 matches in 28s, 0 easy wins / max 39 — the honest result of an NIH-heavy 200-grant corpus vs NH service nonprofits; engine mechanics verified, corpus breadth is the next lever. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@novelpad/outreach-worker
DBOS executor process for the HelmDocs grant-match outreach engine. Runs the
scheduled workflows that keep the outreach schema's grant catalog fresh —
nightly ingestion from upstream sources and an hourly expiry sweep — decoupled
from any HTTP-facing app in this monorepo (mirrors the workflow-worker split
in novelpad-desktop).
Boot order (load-bearing)
src/main.ts imports ./workflows/ingest-grants.js and
./workflows/expire-grants.js before calling DBOS.launch(). Each of
those modules calls DBOS.registerWorkflow + DBOS.registerScheduled at
module-evaluation time — DBOS only dispatches scheduled/queued jobs for
functions that were registered before launch, so importing them after launch
(or not at all) silently means the cron jobs never fire.
The db handle is then threaded into each workflow module via its
set*Deps injector (setIngestGrantsDeps / setExpireGrantsDeps), also
before launch — DBOS serializes scheduled-function arguments, so a Drizzle
client can't be passed through the scheduler call itself. This is the same
module-scope-registry pattern novelpad-desktop's workflow-worker uses for
setStartDeps.
1. import workflow modules → registers ingestGrants / expireGrants
2. build pg Pool + drizzle(db)
3. set*Deps({ db }) → populates each workflow's registry
4. DBOS.setConfig(...)
5. DBOS.launch() → scheduler starts firing
Workflows
ingestGrants(0 3 * * *, nightly) —fetchGrantsGov(stub; real implementation calls the Grants.gov Search2 API,POST https://api.grants.gov/v1/api/search2) →normalize→ upsert viaserverInsertGrantsfrom@novelpad/outreach-core/server. NH state postings and 990-PF extracts land as additional fetch+normalize steps later.expireGrants(0 * * * *, hourly) — marks grants whose close date has passed as closed viaserverExpireClosedGrants, so they drop out of the active match/scoring pool.
Both are registered as a DBOS workflow and a scheduled function referencing
the same function object (DBOS.registerWorkflow then DBOS.registerScheduled)
— see the doc comments in src/workflows/*.ts for why the dual registration
is required.
Scripts
yarn dev—node --env-file=.env --env-file-if-exists=.env.local --import tsx/esm ./src/main.tsyarn build— esbuild bundle tobuild/main.js(--packages=external)yarn start— run the built bundleyarn typecheck—tsc --noEmit
Environment
Copy .env.example to .env and fill in DATABASE_URL (required — main.ts
throws on boot without it) and GCP_SERVICE_ACCOUNT_KEY_PATH (used by
future ingestion/scoring steps that call Google-hosted APIs).