Skip to content

@gj-kit/nest-operations-jobs recipes

Each code block reuses a public-contract example already type-checked in the package README.

1. Register an authenticated operations trigger

Section titled “1. Register an authenticated operations trigger”

Provide a run store and explicit authentication before exposing the trigger route.

Outcome: An authenticated operations boundary backed by application-owned run storage.

Application-owned boundary: Implement JobRunStore, then configure a 32+ character shared secret or a token verifier before module registration.

import { OperationsJobsModule, type JobRunStore } from '@gj-kit/nest-operations-jobs';
declare const store: JobRunStore; // Your database-backed run store.
declare const secret: string; // At least 32 characters; keep it outside source control.
export const operations = OperationsJobsModule.forRoot({
store,
auth: { secret },
trigger: { path: 'internal/jobs' },
});

Switch on status before accessing branch-specific error, reason, and recording fields.

error is unreachable until status is narrowed, and recorded sits on every branch because a stored row that disagrees with the returned status is exactly what deserves a page.

import type { JobExecutionResult } from '@gj-kit/nest-operations-jobs/core';
declare const result: JobExecutionResult; // await runner.execute(...)
declare function pageOncall(jobKey: string, runId: string): void; // the app owns this
export function report(): void {
// console.error(result.error.code);
// -> error TS2339: Property 'error' does not exist on type 'JobExecutionResult'.
if (result.status === 'TIMED_OUT') {
console.error(result.jobKey, result.error.code); // 'ERR_JOB_TIMEOUT'
} else if (result.status === 'SKIPPED') {
console.warn(result.jobKey, result.reason); // 'overlap' - the only value
}
// `recorded` sits on every branch: 'superseded' means a reaper already
// finalised the row, so a second body may run under a different runId.
if (result.recorded === 'superseded') pageOncall(result.jobKey, result.runId);
}

Use the complete API reference for every export and import path.