Skip to main content

Class: JobScheduler

Defined in: packages/client/src/core/job-engine/scheduler.ts:168

Decides when the jobs an application has approved should run, and dispatches them.

Mounted at stack.jobScheduler, but never started by the stack: what may run unattended is the application's decision.

Example

stack.jobScheduler.start({
jobs: ["Job-review-campaign", "Job-cross-sell"],
pinnedHashes: { "Job-review-campaign": "9f2c…" },
});

// Wake sources are the application's, because `core/` imports no DOM:
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible") void stack.jobScheduler.tick();
});

Constructors

Constructor

new JobScheduler(host): JobScheduler;

Defined in: packages/client/src/core/job-engine/scheduler.ts:184

Parameters

ParameterType
hostSchedulerHost

Returns

JobScheduler

Accessors

isRunning

Get Signature

get isRunning(): boolean;

Defined in: packages/client/src/core/job-engine/scheduler.ts:230

Whether start is in effect.

Returns

boolean

Methods

drain()

drain(): Promise<void>;

Defined in: packages/client/src/core/job-engine/scheduler.ts:251

Resolves when every job this scheduler started has finished. For teardown and tests.

Returns

Promise<void>


start()

start(options): void;

Defined in: packages/client/src/core/job-engine/scheduler.ts:194

Begins scheduling, and evaluates once immediately.

The immediate evaluation is the point: a client's most reliable clock signal is "the app just opened", not a timer that was frozen while it was closed.

Parameters

ParameterType
optionsSchedulerOptions

Returns

void


status()

status(): object;

Defined in: packages/client/src/core/job-engine/scheduler.ts:258

What the scheduler believes, without touching the database.

Returns

object

NameTypeDefined in
inFlightstring[]packages/client/src/core/job-engine/scheduler.ts:258
jobsRecord<string, JobScheduleState>packages/client/src/core/job-engine/scheduler.ts:258
runningbooleanpackages/client/src/core/job-engine/scheduler.ts:258

stop()

stop(): void;

Defined in: packages/client/src/core/job-engine/scheduler.ts:220

Stops scheduling. Jobs already dispatched keep running — a hydrated new Function has no cancellation, and pretending otherwise would leave a RUNNING run behind.

Returns

void


tick()

tick(): Promise<TickReport>;

Defined in: packages/client/src/core/job-engine/scheduler.ts:241

Evaluates every allowed job and dispatches those that are due.

Idempotent and safe to call from any wake signal. Concurrent calls share one evaluation. It returns once dispatch has started: a long job does not hold the tick open, because a tick that waits is a tick that stops the others.

Returns

Promise<TickReport>