Base scheduling engine providing metadata caching for MemberJunction's scheduled jobs system. Loads and caches job types, scheduled jobs, and recent runs. Can be used on both client and server.
graph TD
subgraph "@memberjunction/scheduling-engine-base"
A[SchedulingEngineBase] --> B[Job Types Cache]
A --> C[Scheduled Jobs Cache]
A --> D[Job Runs Cache]
A --> E[Polling Interval
Calculator]
F[MJScheduledJobEntityExtended] --> A
end
subgraph "Data Sources"
G["MJ: Scheduled Job Types"]
H["MJ: Scheduled Jobs"]
I["MJ: Scheduled Job Runs"]
end
G --> B
H --> C
I --> D
J["@memberjunction/scheduling-engine
(Server Execution)"] -->|extends| A
style A fill:#2d6a9f,stroke:#1a4971,color:#fff
style B fill:#2d8659,stroke:#1a5c3a,color:#fff
style C fill:#2d8659,stroke:#1a5c3a,color:#fff
style D fill:#2d8659,stroke:#1a5c3a,color:#fff
style E fill:#7c5295,stroke:#563a6b,color:#fff
style F fill:#b8762f,stroke:#8a5722,color:#fff
style J fill:#7c5295,stroke:#563a6b,color:#fff
This package provides two main components:
A singleton engine that extends BaseEngine to load and cache scheduling metadata:
An extended entity class registered via @RegisterClass that adds helper properties and methods to ScheduledJobEntity:
IsLocked, IsLockStale, CurrentLockHolder propertiesAllowsConcurrent, QueuesOverlappingRuns, SkipsOverlappingRunsSuccessRate, FailureRate percentage calculationsGetTimeUntilNextRun() millisecond calculationSave() and Delete() to auto-refresh engine metadata and recalculate polling intervalsnpm install @memberjunction/scheduling-engine-base
import { SchedulingEngineBase } from '@memberjunction/scheduling-engine-base';
const engine = SchedulingEngineBase.Instance;
// Load active jobs only (default)
await engine.Config(false, contextUser);
// Load all jobs with recent runs
await engine.Config(false, contextUser, undefined, true, true);
// Job types (plugin registry)
const jobTypes = engine.ScheduledJobTypes;
const agentType = engine.GetJobTypeByName('Agent');
const byDriver = engine.GetJobTypeByDriverClass('ScheduledJobAgent');
// Scheduled jobs
const activeJobs = engine.ScheduledJobs;
const agentJobs = engine.GetJobsByType(agentType.ID);
// Job runs
const runs = engine.GetRunsForJob(jobId);
// Adaptive polling
engine.UpdatePollingInterval();
const interval = engine.ActivePollingInterval; // ms, or null if no jobs
import { MJScheduledJobEntityExtended } from '@memberjunction/scheduling-engine-base';
const job = activeJobs[0] as MJScheduledJobEntityExtended;
console.log(job.IsLocked); // Is currently being executed?
console.log(job.IsLockStale); // Has the lock expired?
console.log(job.SuccessRate); // e.g., 95.5
console.log(job.AllowsConcurrent); // Can run in parallel?
console.log(job.GetTimeUntilNextRun()); // ms until next execution
| Member | Type | Description |
|---|---|---|
Instance |
static getter | Singleton instance |
Config() |
method | Load scheduling metadata with options |
ScheduledJobTypes |
getter | All job type definitions |
ScheduledJobs |
getter | Active (or all) scheduled jobs |
ScheduledJobRuns |
getter | Recent job runs (if loaded) |
GetJobTypeByName() |
method | Find job type by name |
GetJobTypeByDriverClass() |
method | Find job type by driver class |
GetJobsByType() |
method | Get all jobs of a specific type |
GetRunsForJob() |
method | Get runs for a specific job |
ActivePollingInterval |
getter | Current polling interval (ms) or null |
UpdatePollingInterval() |
method | Recalculate optimal polling interval |
graph LR
A["base-types
(Interfaces)"] --> B["base-engine
(Metadata Cache)"]
B --> C["engine
(Execution)"]
A --> D["actions
(Agentic Tools)"]
style A fill:#2d6a9f,stroke:#1a4971,color:#fff
style B fill:#2d8659,stroke:#1a5c3a,color:#fff
style C fill:#7c5295,stroke:#563a6b,color:#fff
style D fill:#b8762f,stroke:#8a5722,color:#fff
| Package | Purpose |
|---|---|
@memberjunction/core |
BaseEngine, UserInfo, IMetadataProvider |
@memberjunction/core-entities |
ScheduledJobEntity, ScheduledJobTypeEntity, ScheduledJobRunEntity |
@memberjunction/global |
RegisterClass decorator |
@memberjunction/scheduling-base-types |
Shared type definitions |
ISC
Fileoverview
Main export for Scheduling Engine Base