@memberjunction/scheduling-engine-base 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +161 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # @memberjunction/scheduling-engine-base
2
+
3
+ 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.
4
+
5
+ ## Architecture
6
+
7
+ ```mermaid
8
+ graph TD
9
+ subgraph "@memberjunction/scheduling-engine-base"
10
+ A[SchedulingEngineBase] --> B[Job Types Cache]
11
+ A --> C[Scheduled Jobs Cache]
12
+ A --> D[Job Runs Cache]
13
+ A --> E[Polling Interval<br/>Calculator]
14
+ F[ScheduledJobEntityExtended] --> A
15
+ end
16
+
17
+ subgraph "Data Sources"
18
+ G["MJ: Scheduled Job Types"]
19
+ H["MJ: Scheduled Jobs"]
20
+ I["MJ: Scheduled Job Runs"]
21
+ end
22
+
23
+ G --> B
24
+ H --> C
25
+ I --> D
26
+
27
+ J["@memberjunction/scheduling-engine<br/>(Server Execution)"] -->|extends| A
28
+
29
+ style A fill:#2d6a9f,stroke:#1a4971,color:#fff
30
+ style B fill:#2d8659,stroke:#1a5c3a,color:#fff
31
+ style C fill:#2d8659,stroke:#1a5c3a,color:#fff
32
+ style D fill:#2d8659,stroke:#1a5c3a,color:#fff
33
+ style E fill:#7c5295,stroke:#563a6b,color:#fff
34
+ style F fill:#b8762f,stroke:#8a5722,color:#fff
35
+ style J fill:#7c5295,stroke:#563a6b,color:#fff
36
+ ```
37
+
38
+ ## Overview
39
+
40
+ This package provides two main components:
41
+
42
+ ### SchedulingEngineBase
43
+
44
+ A singleton engine that extends `BaseEngine` to load and cache scheduling metadata:
45
+
46
+ - **Job Types**: Plugin registry mapping job type names to driver classes
47
+ - **Scheduled Jobs**: Active (or all) scheduled jobs with their configurations
48
+ - **Job Runs**: Recent execution history (last 7 days, optional)
49
+ - **Polling Interval**: Adaptive polling interval calculation based on next run times
50
+ - **Lookup Methods**: Find job types by name or driver class, get jobs by type, get runs for a job
51
+
52
+ ### ScheduledJobEntityExtended
53
+
54
+ An extended entity class registered via `@RegisterClass` that adds helper properties and methods to `ScheduledJobEntity`:
55
+
56
+ - **Lock Management**: `IsLocked`, `IsLockStale`, `CurrentLockHolder` properties
57
+ - **Concurrency**: `AllowsConcurrent`, `QueuesOverlappingRuns`, `SkipsOverlappingRuns`
58
+ - **Statistics**: `SuccessRate`, `FailureRate` percentage calculations
59
+ - **Timing**: `GetTimeUntilNextRun()` millisecond calculation
60
+ - **Auto-Notifications**: Overrides `Save()` and `Delete()` to auto-refresh engine metadata and recalculate polling intervals
61
+
62
+ ## Installation
63
+
64
+ ```bash
65
+ npm install @memberjunction/scheduling-engine-base
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ### Loading Metadata
71
+
72
+ ```typescript
73
+ import { SchedulingEngineBase } from '@memberjunction/scheduling-engine-base';
74
+
75
+ const engine = SchedulingEngineBase.Instance;
76
+
77
+ // Load active jobs only (default)
78
+ await engine.Config(false, contextUser);
79
+
80
+ // Load all jobs with recent runs
81
+ await engine.Config(false, contextUser, undefined, true, true);
82
+ ```
83
+
84
+ ### Accessing Cached Data
85
+
86
+ ```typescript
87
+ // Job types (plugin registry)
88
+ const jobTypes = engine.ScheduledJobTypes;
89
+ const agentType = engine.GetJobTypeByName('Agent');
90
+ const byDriver = engine.GetJobTypeByDriverClass('ScheduledJobAgent');
91
+
92
+ // Scheduled jobs
93
+ const activeJobs = engine.ScheduledJobs;
94
+ const agentJobs = engine.GetJobsByType(agentType.ID);
95
+
96
+ // Job runs
97
+ const runs = engine.GetRunsForJob(jobId);
98
+
99
+ // Adaptive polling
100
+ engine.UpdatePollingInterval();
101
+ const interval = engine.ActivePollingInterval; // ms, or null if no jobs
102
+ ```
103
+
104
+ ### Using Extended Entity
105
+
106
+ ```typescript
107
+ import { ScheduledJobEntityExtended } from '@memberjunction/scheduling-engine-base';
108
+
109
+ const job = activeJobs[0] as ScheduledJobEntityExtended;
110
+
111
+ console.log(job.IsLocked); // Is currently being executed?
112
+ console.log(job.IsLockStale); // Has the lock expired?
113
+ console.log(job.SuccessRate); // e.g., 95.5
114
+ console.log(job.AllowsConcurrent); // Can run in parallel?
115
+ console.log(job.GetTimeUntilNextRun()); // ms until next execution
116
+ ```
117
+
118
+ ## API Reference
119
+
120
+ ### SchedulingEngineBase
121
+
122
+ | Member | Type | Description |
123
+ |--------|------|-------------|
124
+ | `Instance` | static getter | Singleton instance |
125
+ | `Config()` | method | Load scheduling metadata with options |
126
+ | `ScheduledJobTypes` | getter | All job type definitions |
127
+ | `ScheduledJobs` | getter | Active (or all) scheduled jobs |
128
+ | `ScheduledJobRuns` | getter | Recent job runs (if loaded) |
129
+ | `GetJobTypeByName()` | method | Find job type by name |
130
+ | `GetJobTypeByDriverClass()` | method | Find job type by driver class |
131
+ | `GetJobsByType()` | method | Get all jobs of a specific type |
132
+ | `GetRunsForJob()` | method | Get runs for a specific job |
133
+ | `ActivePollingInterval` | getter | Current polling interval (ms) or null |
134
+ | `UpdatePollingInterval()` | method | Recalculate optimal polling interval |
135
+
136
+ ## Relationship to Other Scheduling Packages
137
+
138
+ ```mermaid
139
+ graph LR
140
+ A["base-types<br/>(Interfaces)"] --> B["base-engine<br/>(Metadata Cache)"]
141
+ B --> C["engine<br/>(Execution)"]
142
+ A --> D["actions<br/>(Agentic Tools)"]
143
+
144
+ style A fill:#2d6a9f,stroke:#1a4971,color:#fff
145
+ style B fill:#2d8659,stroke:#1a5c3a,color:#fff
146
+ style C fill:#7c5295,stroke:#563a6b,color:#fff
147
+ style D fill:#b8762f,stroke:#8a5722,color:#fff
148
+ ```
149
+
150
+ ## Dependencies
151
+
152
+ | Package | Purpose |
153
+ |---------|---------|
154
+ | `@memberjunction/core` | BaseEngine, UserInfo, IMetadataProvider |
155
+ | `@memberjunction/core-entities` | ScheduledJobEntity, ScheduledJobTypeEntity, ScheduledJobRunEntity |
156
+ | `@memberjunction/global` | RegisterClass decorator |
157
+ | `@memberjunction/scheduling-base-types` | Shared type definitions |
158
+
159
+ ## License
160
+
161
+ ISC
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/scheduling-engine-base",
3
3
  "type": "module",
4
- "version": "4.0.0",
4
+ "version": "4.2.0",
5
5
  "description": "MemberJunction: Base Scheduling Engine Package - extended entity types and metadata caching, can be used anywhere.",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -15,10 +15,10 @@
15
15
  "author": "MemberJunction.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@memberjunction/core": "4.0.0",
19
- "@memberjunction/global": "4.0.0",
20
- "@memberjunction/core-entities": "4.0.0",
21
- "@memberjunction/scheduling-base-types": "4.0.0"
18
+ "@memberjunction/core": "4.2.0",
19
+ "@memberjunction/global": "4.2.0",
20
+ "@memberjunction/core-entities": "4.2.0",
21
+ "@memberjunction/scheduling-base-types": "4.2.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "24.10.11",