@memberjunction/queue 3.4.0 → 4.1.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.
- package/README.md +129 -262
- package/dist/drivers/AIActionQueue.d.ts +1 -1
- package/dist/drivers/AIActionQueue.js +13 -16
- package/dist/drivers/AIActionQueue.js.map +1 -1
- package/dist/generic/QueueBase.js +9 -15
- package/dist/generic/QueueBase.js.map +1 -1
- package/dist/generic/QueueManager.d.ts +1 -1
- package/dist/generic/QueueManager.js +21 -28
- package/dist/generic/QueueManager.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -21
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
# @memberjunction/queue
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A server-side queue management framework for MemberJunction applications that provides database-backed task persistence, concurrent processing, and heartbeat monitoring.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The `@memberjunction/queue` package
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
The `@memberjunction/queue` package delivers a robust queuing system for background task processing. It manages task lifecycle from creation through execution, with automatic queue provisioning, configurable concurrency limits, and process-level health tracking.
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
graph TD
|
|
11
|
+
A["QueueManager<br/>(Singleton)"] --> B["QueueBase<br/>(Abstract)"]
|
|
12
|
+
B --> C["AIActionQueue"]
|
|
13
|
+
B --> D["EntityAIActionQueue"]
|
|
14
|
+
B --> E["Custom Queue<br/>(Your Implementation)"]
|
|
15
|
+
|
|
16
|
+
A --> F["Queue Types<br/>(Database Metadata)"]
|
|
17
|
+
A --> G["Queue Records<br/>(Process Tracking)"]
|
|
18
|
+
B --> H["TaskBase<br/>(Individual Tasks)"]
|
|
19
|
+
|
|
20
|
+
style A fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
21
|
+
style B fill:#7c5295,stroke:#563a6b,color:#fff
|
|
22
|
+
style C fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
23
|
+
style D fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
24
|
+
style E fill:#b8762f,stroke:#8a5722,color:#fff
|
|
25
|
+
style F fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
26
|
+
style G fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
27
|
+
style H fill:#7c5295,stroke:#563a6b,color:#fff
|
|
28
|
+
```
|
|
15
29
|
|
|
16
30
|
## Installation
|
|
17
31
|
|
|
@@ -19,319 +33,172 @@ The `@memberjunction/queue` package provides a robust framework for implementing
|
|
|
19
33
|
npm install @memberjunction/queue
|
|
20
34
|
```
|
|
21
35
|
|
|
22
|
-
##
|
|
23
|
-
|
|
24
|
-
This package requires the following MemberJunction packages:
|
|
25
|
-
|
|
26
|
-
- `@memberjunction/core` - Core functionality and entity management
|
|
27
|
-
- `@memberjunction/global` - Global utilities and class registration
|
|
28
|
-
- `@memberjunction/core-entities` - Entity type definitions
|
|
29
|
-
- `@memberjunction/ai` - AI functionality (for AI-related queues)
|
|
30
|
-
- `@memberjunction/aiengine` - AI Engine integration
|
|
31
|
-
|
|
32
|
-
Additional dependencies:
|
|
33
|
-
- `uuid` - For generating unique identifiers
|
|
34
|
-
|
|
35
|
-
## Core Components
|
|
36
|
-
|
|
37
|
-
### TaskBase
|
|
36
|
+
## Architecture
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
### Task Lifecycle
|
|
40
39
|
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// Properties
|
|
50
|
-
ID: string // Unique task identifier
|
|
51
|
-
Status: TaskStatus // Current task status
|
|
52
|
-
Data: any // Task payload data
|
|
53
|
-
Options: TaskOptions // Task configuration
|
|
54
|
-
TaskRecord: QueueTaskEntity // Database entity
|
|
55
|
-
}
|
|
40
|
+
```mermaid
|
|
41
|
+
stateDiagram-v2
|
|
42
|
+
[*] --> Pending: Task Created
|
|
43
|
+
Pending --> InProgress: Queue Picks Up
|
|
44
|
+
InProgress --> Complete: ProcessTask Succeeds
|
|
45
|
+
InProgress --> Failed: ProcessTask Fails
|
|
46
|
+
Pending --> Cancelled: External Cancel
|
|
56
47
|
```
|
|
57
48
|
|
|
58
|
-
###
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
### Processing Flow
|
|
50
|
+
|
|
51
|
+
```mermaid
|
|
52
|
+
sequenceDiagram
|
|
53
|
+
participant Client
|
|
54
|
+
participant QM as QueueManager
|
|
55
|
+
participant QB as QueueBase
|
|
56
|
+
participant DB as Database
|
|
57
|
+
|
|
58
|
+
Client->>QM: AddTask(type, data, options)
|
|
59
|
+
QM->>QM: Find or create queue for type
|
|
60
|
+
QM->>DB: Save QueueTask record (Pending)
|
|
61
|
+
QM->>QB: AddTask(taskBase)
|
|
62
|
+
QB->>QB: ProcessTasks() loop (250ms interval)
|
|
63
|
+
QB->>QB: Check concurrency (max 3 tasks)
|
|
64
|
+
QB->>QB: StartTask(task)
|
|
65
|
+
QB->>QB: ProcessTask(task) [abstract]
|
|
66
|
+
QB->>DB: Update QueueTask status
|
|
67
|
+
QB-->>Client: TaskResult
|
|
70
68
|
```
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
The abstract `QueueBase` class serves as the foundation for all queue implementations:
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
export abstract class QueueBase {
|
|
78
|
-
constructor(
|
|
79
|
-
QueueRecord: QueueEntity,
|
|
80
|
-
QueueTypeID: string,
|
|
81
|
-
ContextUser: UserInfo
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
// Public methods
|
|
85
|
-
AddTask(task: TaskBase): boolean
|
|
86
|
-
FindTask(ID: string): TaskBase
|
|
87
|
-
|
|
88
|
-
// Protected abstract method to implement
|
|
89
|
-
protected abstract ProcessTask(
|
|
90
|
-
task: TaskBase,
|
|
91
|
-
contextUser: UserInfo
|
|
92
|
-
): Promise<TaskResult>
|
|
93
|
-
}
|
|
94
|
-
```
|
|
70
|
+
## Core Components
|
|
95
71
|
|
|
96
72
|
### QueueManager
|
|
97
73
|
|
|
98
|
-
The `QueueManager` is a singleton that
|
|
74
|
+
The `QueueManager` is a singleton that coordinates all active queues. It auto-creates queue instances per type and captures process-level metadata (PID, hostname, network interfaces) for monitoring.
|
|
99
75
|
|
|
100
76
|
```typescript
|
|
101
|
-
|
|
102
|
-
// Singleton access
|
|
103
|
-
static get Instance(): QueueManager
|
|
104
|
-
|
|
105
|
-
// Static methods
|
|
106
|
-
static async Config(contextUser: UserInfo): Promise<void>
|
|
107
|
-
static async AddTask(
|
|
108
|
-
QueueType: string,
|
|
109
|
-
data: any,
|
|
110
|
-
options: any,
|
|
111
|
-
contextUser: UserInfo
|
|
112
|
-
): Promise<TaskBase | undefined>
|
|
113
|
-
|
|
114
|
-
// Instance methods
|
|
115
|
-
async AddTask(
|
|
116
|
-
QueueTypeID: string,
|
|
117
|
-
data: any,
|
|
118
|
-
options: any,
|
|
119
|
-
contextUser: UserInfo
|
|
120
|
-
): Promise<TaskBase | undefined>
|
|
121
|
-
}
|
|
122
|
-
```
|
|
77
|
+
import { QueueManager } from '@memberjunction/queue';
|
|
123
78
|
|
|
124
|
-
|
|
79
|
+
// Initialize (typically at application startup)
|
|
80
|
+
await QueueManager.Config(contextUser);
|
|
125
81
|
|
|
126
|
-
|
|
82
|
+
// Add a task by queue type name
|
|
83
|
+
const task = await QueueManager.AddTask(
|
|
84
|
+
'Email Notification',
|
|
85
|
+
{ recipient: 'user@example.com', subject: 'Welcome' },
|
|
86
|
+
{ priority: 1 },
|
|
87
|
+
contextUser
|
|
88
|
+
);
|
|
127
89
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
success: boolean // Whether task completed successfully
|
|
131
|
-
userMessage: string // User-friendly message
|
|
132
|
-
output: any // Task output data
|
|
133
|
-
exception: any // Exception details if failed
|
|
90
|
+
if (task) {
|
|
91
|
+
console.log(`Task created: ${task.ID}`);
|
|
134
92
|
}
|
|
135
93
|
```
|
|
136
94
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
### Basic Queue Implementation
|
|
95
|
+
### QueueBase
|
|
140
96
|
|
|
141
|
-
|
|
97
|
+
Abstract base class for all queue implementations. Subclasses implement `ProcessTask()` to define task execution logic.
|
|
142
98
|
|
|
143
99
|
```typescript
|
|
144
100
|
import { QueueBase, TaskBase, TaskResult } from '@memberjunction/queue';
|
|
145
101
|
import { RegisterClass } from '@memberjunction/global';
|
|
146
102
|
import { UserInfo } from '@memberjunction/core';
|
|
147
103
|
|
|
148
|
-
// Register your queue with a specific queue type name
|
|
149
104
|
@RegisterClass(QueueBase, 'Email Notification')
|
|
150
105
|
export class EmailNotificationQueue extends QueueBase {
|
|
151
106
|
protected async ProcessTask(
|
|
152
|
-
task: TaskBase,
|
|
107
|
+
task: TaskBase,
|
|
153
108
|
contextUser: UserInfo
|
|
154
109
|
): Promise<TaskResult> {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// Simulate email sending
|
|
164
|
-
await this.sendEmail(recipient, subject, body);
|
|
165
|
-
|
|
166
|
-
// Return success result
|
|
167
|
-
return {
|
|
168
|
-
success: true,
|
|
169
|
-
userMessage: 'Email sent successfully',
|
|
170
|
-
output: { sentAt: new Date() },
|
|
171
|
-
exception: null
|
|
172
|
-
};
|
|
173
|
-
} catch (error) {
|
|
174
|
-
// Return failure result
|
|
175
|
-
return {
|
|
176
|
-
success: false,
|
|
177
|
-
userMessage: `Failed to send email: ${error.message}`,
|
|
178
|
-
output: null,
|
|
179
|
-
exception: error
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
private async sendEmail(to: string, subject: string, body: string) {
|
|
185
|
-
// Your email service integration here
|
|
110
|
+
const { recipient, subject, body } = task.Data;
|
|
111
|
+
await sendEmail(recipient, subject, body);
|
|
112
|
+
return {
|
|
113
|
+
success: true,
|
|
114
|
+
userMessage: 'Email sent successfully',
|
|
115
|
+
output: { sentAt: new Date() },
|
|
116
|
+
exception: null
|
|
117
|
+
};
|
|
186
118
|
}
|
|
187
119
|
}
|
|
188
120
|
```
|
|
189
121
|
|
|
190
|
-
###
|
|
122
|
+
### TaskBase
|
|
191
123
|
|
|
192
|
-
|
|
193
|
-
import { QueueManager } from '@memberjunction/queue';
|
|
194
|
-
import { UserInfo } from '@memberjunction/core';
|
|
124
|
+
Represents an individual task with its payload, options, and database-backed record.
|
|
195
125
|
|
|
196
|
-
|
|
197
|
-
|
|
126
|
+
| Property | Type | Description |
|
|
127
|
+
|----------|------|-------------|
|
|
128
|
+
| `ID` | `string` | Unique task identifier from database |
|
|
129
|
+
| `Status` | `TaskStatus` | Current status (Pending, InProgress, Complete, Failed, Cancelled) |
|
|
130
|
+
| `Data` | `object` | Task payload data |
|
|
131
|
+
| `Options` | `TaskOptions` | Configuration (e.g., priority) |
|
|
132
|
+
| `TaskRecord` | `QueueTaskEntity` | Underlying database entity |
|
|
198
133
|
|
|
199
|
-
|
|
200
|
-
const task = await QueueManager.AddTask(
|
|
201
|
-
'Email Notification', // Queue type name
|
|
202
|
-
{ // Task data
|
|
203
|
-
recipient: 'user@example.com',
|
|
204
|
-
subject: 'Welcome to MemberJunction',
|
|
205
|
-
body: 'Thank you for joining!'
|
|
206
|
-
},
|
|
207
|
-
{ // Task options
|
|
208
|
-
priority: 1
|
|
209
|
-
},
|
|
210
|
-
contextUser
|
|
211
|
-
);
|
|
134
|
+
### TaskResult
|
|
212
135
|
|
|
213
|
-
|
|
214
|
-
console.log(`Task created with ID: ${task.ID}`);
|
|
215
|
-
}
|
|
216
|
-
```
|
|
136
|
+
Returned by `ProcessTask()` to communicate outcome.
|
|
217
137
|
|
|
218
|
-
|
|
138
|
+
| Property | Type | Description |
|
|
139
|
+
|----------|------|-------------|
|
|
140
|
+
| `success` | `boolean` | Whether the task completed successfully |
|
|
141
|
+
| `userMessage` | `string` | Human-readable result message |
|
|
142
|
+
| `output` | `object` | Task output data |
|
|
143
|
+
| `exception` | `object` | Error details if failed |
|
|
219
144
|
|
|
220
|
-
|
|
145
|
+
## Built-in Queues
|
|
221
146
|
|
|
222
|
-
|
|
223
|
-
|
|
147
|
+
### AIActionQueue
|
|
148
|
+
|
|
149
|
+
Processes AI actions through the MemberJunction AI Engine.
|
|
224
150
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const aiTask = await QueueManager.AddTask(
|
|
151
|
+
```typescript
|
|
152
|
+
const task = await QueueManager.AddTask(
|
|
228
153
|
'AI Action',
|
|
229
|
-
{
|
|
230
|
-
actionName: 'GenerateText',
|
|
231
|
-
prompt: 'Write a product description',
|
|
232
|
-
parameters: { maxTokens: 100 }
|
|
233
|
-
},
|
|
154
|
+
{ actionName: 'GenerateText', prompt: 'Summarize this document' },
|
|
234
155
|
{},
|
|
235
156
|
contextUser
|
|
236
157
|
);
|
|
158
|
+
```
|
|
237
159
|
|
|
238
|
-
|
|
239
|
-
|
|
160
|
+
### EntityAIActionQueue
|
|
161
|
+
|
|
162
|
+
Processes entity-specific AI actions.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
const task = await QueueManager.AddTask(
|
|
240
166
|
'Entity AI Action',
|
|
241
|
-
{
|
|
242
|
-
entityName: 'Products',
|
|
243
|
-
entityID: 123,
|
|
244
|
-
actionName: 'GenerateDescription'
|
|
245
|
-
},
|
|
167
|
+
{ entityName: 'Products', entityID: '123', actionName: 'GenerateDescription' },
|
|
246
168
|
{},
|
|
247
169
|
contextUser
|
|
248
170
|
);
|
|
249
171
|
```
|
|
250
172
|
|
|
251
|
-
## Database Schema
|
|
252
|
-
|
|
253
|
-
The queue system requires the following database tables:
|
|
254
|
-
|
|
255
|
-
### Queue Types Table (`__mj.QueueType`)
|
|
256
|
-
Stores definitions of different queue types (e.g., "Email Notification", "AI Action")
|
|
257
|
-
|
|
258
|
-
### Queues Table (`__mj.Queue`)
|
|
259
|
-
Tracks active queue instances with process information:
|
|
260
|
-
- Queue type reference
|
|
261
|
-
- Process details (PID, platform, hostname)
|
|
262
|
-
- Heartbeat timestamp
|
|
263
|
-
- Network information
|
|
264
|
-
|
|
265
|
-
### Queue Tasks Table (`__mj.QueueTask`)
|
|
266
|
-
Stores individual tasks:
|
|
267
|
-
- Queue reference
|
|
268
|
-
- Task status
|
|
269
|
-
- Task data (JSON)
|
|
270
|
-
- Task options (JSON)
|
|
271
|
-
- Output and error information
|
|
272
|
-
|
|
273
|
-
## Process Management
|
|
274
|
-
|
|
275
|
-
The QueueManager automatically captures process information for monitoring:
|
|
276
|
-
- Process ID (PID)
|
|
277
|
-
- Platform and version
|
|
278
|
-
- Working directory
|
|
279
|
-
- Network interfaces
|
|
280
|
-
- Operating system details
|
|
281
|
-
- User information
|
|
282
|
-
- Heartbeat timestamps
|
|
283
|
-
|
|
284
|
-
This information helps track queue health and enables failover scenarios.
|
|
285
|
-
|
|
286
173
|
## Configuration
|
|
287
174
|
|
|
288
|
-
Queue behavior
|
|
175
|
+
Queue behavior is controlled through constructor parameters:
|
|
289
176
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
// Override these values in your constructor
|
|
296
|
-
constructor(QueueRecord: QueueEntity, QueueTypeID: string, ContextUser: UserInfo) {
|
|
297
|
-
super(QueueRecord, QueueTypeID, ContextUser);
|
|
298
|
-
// Customize queue behavior
|
|
299
|
-
this._maxTasks = 10;
|
|
300
|
-
this._checkInterval = 1000;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
## Best Practices
|
|
306
|
-
|
|
307
|
-
1. **Task Data Structure**: Keep task data serializable as JSON
|
|
308
|
-
2. **Error Handling**: Always return proper TaskResult with error details
|
|
309
|
-
3. **Queue Registration**: Use `@RegisterClass` decorator for automatic registration
|
|
310
|
-
4. **Idempotency**: Design tasks to be safely retryable
|
|
311
|
-
5. **Resource Cleanup**: Clean up resources in finally blocks
|
|
312
|
-
6. **Monitoring**: Check heartbeat timestamps for queue health
|
|
313
|
-
|
|
314
|
-
## Integration with MemberJunction
|
|
177
|
+
| Parameter | Default | Description |
|
|
178
|
+
|-----------|---------|-------------|
|
|
179
|
+
| `_maxTasks` | `3` | Maximum concurrent tasks per queue |
|
|
180
|
+
| `_checkInterval` | `250` | Polling interval in milliseconds |
|
|
315
181
|
|
|
316
|
-
|
|
317
|
-
- **Entity System**: Use entities for task data and processing
|
|
318
|
-
- **User Context**: All operations respect user permissions
|
|
319
|
-
- **Global Registry**: Automatic queue discovery via class registration
|
|
320
|
-
- **AI Engine**: Built-in support for AI task processing
|
|
182
|
+
## Database Schema
|
|
321
183
|
|
|
322
|
-
|
|
184
|
+
The queue system persists state across three tables:
|
|
323
185
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
186
|
+
| Table | Purpose |
|
|
187
|
+
|-------|---------|
|
|
188
|
+
| `__mj.QueueType` | Defines available queue types |
|
|
189
|
+
| `__mj.Queue` | Tracks active queue instances with process info and heartbeat |
|
|
190
|
+
| `__mj.QueueTask` | Stores individual tasks with status, data, and output |
|
|
327
191
|
|
|
328
|
-
|
|
329
|
-
npm run start
|
|
192
|
+
## Dependencies
|
|
330
193
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
194
|
+
| Package | Purpose |
|
|
195
|
+
|---------|---------|
|
|
196
|
+
| `@memberjunction/core` | Entity management and metadata |
|
|
197
|
+
| `@memberjunction/global` | Class registration and global state |
|
|
198
|
+
| `@memberjunction/core-entities` | Queue and task entity types |
|
|
199
|
+
| `@memberjunction/ai` | AI functionality for built-in queues |
|
|
200
|
+
| `@memberjunction/aiengine` | AI Engine integration |
|
|
334
201
|
|
|
335
202
|
## License
|
|
336
203
|
|
|
337
|
-
ISC
|
|
204
|
+
ISC
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { QueueBase, TaskBase, TaskResult } from "../generic/QueueBase";
|
|
1
|
+
import { QueueBase, TaskBase, TaskResult } from "../generic/QueueBase.js";
|
|
2
2
|
export declare class AIActionQueue extends QueueBase {
|
|
3
3
|
protected ProcessTask(task: TaskBase): Promise<TaskResult>;
|
|
4
4
|
protected ProcessGeneric(task: TaskBase, entityAIAction: boolean): Promise<TaskResult>;
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const aiengine_1 = require("@memberjunction/aiengine");
|
|
13
|
-
let AIActionQueue = class AIActionQueue extends QueueBase_1.QueueBase {
|
|
7
|
+
import { QueueBase } from "../generic/QueueBase.js";
|
|
8
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
9
|
+
import { AIEngine } from '@memberjunction/aiengine';
|
|
10
|
+
let AIActionQueue = class AIActionQueue extends QueueBase {
|
|
14
11
|
async ProcessTask(task) {
|
|
15
12
|
return this.ProcessGeneric(task, false);
|
|
16
13
|
}
|
|
17
14
|
async ProcessGeneric(task, entityAIAction) {
|
|
18
15
|
try {
|
|
19
|
-
await
|
|
16
|
+
await AIEngine.Instance.Config(false, this._contextUser);
|
|
20
17
|
let result = null;
|
|
21
18
|
if (entityAIAction)
|
|
22
|
-
result = await
|
|
19
|
+
result = await AIEngine.Instance.ExecuteEntityAIAction(task.Data);
|
|
23
20
|
else
|
|
24
|
-
result = await
|
|
21
|
+
result = await AIEngine.Instance.ExecuteAIAction(task.Data);
|
|
25
22
|
return {
|
|
26
23
|
success: result ? result.success : false,
|
|
27
24
|
output: result ? (result.success ? null : result.errorMessage) : null,
|
|
@@ -39,17 +36,17 @@ let AIActionQueue = class AIActionQueue extends QueueBase_1.QueueBase {
|
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(0, global_1.RegisterClass)(QueueBase_1.QueueBase, 'AI Action')
|
|
39
|
+
AIActionQueue = __decorate([
|
|
40
|
+
RegisterClass(QueueBase, 'AI Action')
|
|
45
41
|
], AIActionQueue);
|
|
42
|
+
export { AIActionQueue };
|
|
46
43
|
let EntityAIActionQueue = class EntityAIActionQueue extends AIActionQueue {
|
|
47
44
|
async ProcessTask(task) {
|
|
48
45
|
return this.ProcessGeneric(task, true);
|
|
49
46
|
}
|
|
50
47
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
(0, global_1.RegisterClass)(QueueBase_1.QueueBase, 'Entity AI Action', 1)
|
|
48
|
+
EntityAIActionQueue = __decorate([
|
|
49
|
+
RegisterClass(QueueBase, 'Entity AI Action', 1)
|
|
54
50
|
], EntityAIActionQueue);
|
|
51
|
+
export { EntityAIActionQueue };
|
|
55
52
|
//# sourceMappingURL=AIActionQueue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIActionQueue.js","sourceRoot":"","sources":["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CAAA;QACL,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,IAAI;gBACZ,WAAW,EAAE,mBAAmB,GAAG,CAAC,CAAC,OAAO;gBAC5C,SAAS,EAAE,CAAC;aACf,CAAA;QACL,CAAC;IACL,CAAC;CACJ,CAAA;AA/BY,aAAa;IADzB,aAAa,CAAC,SAAS,EAAE,WAAW,CAAC;GACzB,aAAa,CA+BzB;;AAGM,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,aAAa;IACxC,KAAK,CAAC,WAAW,CAAC,IAAc;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC;CACJ,CAAA;AAJY,mBAAmB;IAD/B,aAAa,CAAC,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC;GACnC,mBAAmB,CAI/B"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueueBase = exports.TaskBase = exports.TaskStatus = exports.TaskResult = void 0;
|
|
4
1
|
//import { QueueTaskEntity, QueueEntity } from 'mj_generatedentities';
|
|
5
|
-
class TaskResult {
|
|
2
|
+
export class TaskResult {
|
|
6
3
|
}
|
|
7
|
-
|
|
8
|
-
exports.TaskStatus = {
|
|
4
|
+
export const TaskStatus = {
|
|
9
5
|
Pending: 'Pending',
|
|
10
6
|
InProgress: 'InProgress',
|
|
11
7
|
Complete: 'Complete',
|
|
12
8
|
Failed: 'Failed',
|
|
13
9
|
Cancelled: 'Cancelled',
|
|
14
10
|
};
|
|
15
|
-
class TaskBase {
|
|
11
|
+
export class TaskBase {
|
|
16
12
|
get Options() {
|
|
17
13
|
return this._options;
|
|
18
14
|
}
|
|
@@ -23,7 +19,7 @@ class TaskBase {
|
|
|
23
19
|
return this._taskRecord.ID;
|
|
24
20
|
}
|
|
25
21
|
constructor(taskRecord, data, options) {
|
|
26
|
-
this._status =
|
|
22
|
+
this._status = TaskStatus.Pending;
|
|
27
23
|
this._taskRecord = taskRecord;
|
|
28
24
|
this._options = options;
|
|
29
25
|
this._data = data;
|
|
@@ -38,8 +34,7 @@ class TaskBase {
|
|
|
38
34
|
this._status = value;
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
class QueueBase {
|
|
37
|
+
export class QueueBase {
|
|
43
38
|
constructor(QueueRecord, QueueTypeID, ContextUser) {
|
|
44
39
|
this._queue = [];
|
|
45
40
|
this._maxTasks = 3; // move to metadata or config param
|
|
@@ -63,8 +58,8 @@ class QueueBase {
|
|
|
63
58
|
// it will re-run itself with a timer to check for new tasks
|
|
64
59
|
// this will be the main loop for the queue
|
|
65
60
|
if (this._queue.length > 0) {
|
|
66
|
-
let processing = this._queue.filter(t => t.Status ===
|
|
67
|
-
let pending = this._queue.filter(t => t.Status ===
|
|
61
|
+
let processing = this._queue.filter(t => t.Status === TaskStatus.InProgress);
|
|
62
|
+
let pending = this._queue.filter(t => t.Status === TaskStatus.Pending);
|
|
68
63
|
// we have room to process one or more additional tasks now
|
|
69
64
|
while (processing.length < this._maxTasks && pending.length > 0) {
|
|
70
65
|
let task = pending.shift();
|
|
@@ -98,7 +93,7 @@ class QueueBase {
|
|
|
98
93
|
async StartTask(task, contextUser) {
|
|
99
94
|
// the process function is responsible for calling the processor function
|
|
100
95
|
try {
|
|
101
|
-
task.Status =
|
|
96
|
+
task.Status = TaskStatus.InProgress; // immediately flag this task so it isn't picked up again...
|
|
102
97
|
// run the task
|
|
103
98
|
let result = await this.ProcessTask(task, contextUser);
|
|
104
99
|
// now set the record data for the DB
|
|
@@ -107,7 +102,7 @@ class QueueBase {
|
|
|
107
102
|
task.TaskRecord.ErrorMessage = result.exception ? JSON.stringify(result.exception) : null;
|
|
108
103
|
await task.TaskRecord.Save();
|
|
109
104
|
// update the task status
|
|
110
|
-
task.Status = result.success ?
|
|
105
|
+
task.Status = result.success ? TaskStatus.Complete : TaskStatus.Failed;
|
|
111
106
|
return result;
|
|
112
107
|
}
|
|
113
108
|
catch (e) {
|
|
@@ -124,5 +119,4 @@ class QueueBase {
|
|
|
124
119
|
return this._queue.find(t => t.ID === ID);
|
|
125
120
|
}
|
|
126
121
|
}
|
|
127
|
-
exports.QueueBase = QueueBase;
|
|
128
122
|
//# sourceMappingURL=QueueBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueBase.js","sourceRoot":"","sources":["../../src/generic/QueueBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueueBase.js","sourceRoot":"","sources":["../../src/generic/QueueBase.ts"],"names":[],"mappings":"AAEA,sEAAsE;AAEtE,MAAM,OAAO,UAAU;CAKtB;AAOD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,WAAW;CACd,CAAC;AAKX,MAAM,OAAO,QAAQ;IAMnB,IAAW,OAAO;QAEhB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IACD,IAAW,IAAI;QAEb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IACD,IAAW,EAAE;QACX,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;IAC7B,CAAC;IACD,YAAa,UAA2B,EAAE,IAAS,EAAE,OAAoB;QAbjE,YAAO,GAAe,UAAU,CAAC,OAAO,CAAC;QAc/C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAW,MAAM;QACf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AM,GAAG,MAAM,CAAC,MAAM,CAAC;YACvC,IAAI,CAAC,UAAU,CAAC,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC1F,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAE7B,yBAAyB;YACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;YAEvE,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACT,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,IAAI;gBACZ,WAAW,EAAE,mBAAmB,GAAG,CAAC,CAAC,OAAO;gBAC5C,SAAS,EAAE,CAAC;aACb,CAAA;QACH,CAAC;IACH,CAAC;IAEM,QAAQ,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.QueueManager = void 0;
|
|
7
1
|
//import { QueueEntity, QueueTaskEntity, QueueTypeEntity } from "mj_generatedentities";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import { TaskBase, QueueBase } from "./QueueBase.js";
|
|
3
|
+
import { LogError, Metadata, RunView } from "@memberjunction/core";
|
|
4
|
+
import { MJGlobal } from "@memberjunction/global";
|
|
5
|
+
import os from 'os';
|
|
12
6
|
/**
|
|
13
7
|
*QueueManager class is a generic manager of all active queues for the process.
|
|
14
8
|
*
|
|
@@ -22,7 +16,9 @@ const os_1 = __importDefault(require("os"));
|
|
|
22
16
|
*information. Heartbeat information is used to determine if a queue has crashed or not by other processes
|
|
23
17
|
*or not. After a heartbeat timeout is reached, other queues can pick up tasks from a crashed process.
|
|
24
18
|
*/
|
|
25
|
-
class QueueManager {
|
|
19
|
+
export class QueueManager {
|
|
20
|
+
static { this._instance = null; }
|
|
21
|
+
static { this._globalInstanceKey = '__mj_queue_manager_instance__'; }
|
|
26
22
|
static get QueueTypes() {
|
|
27
23
|
return QueueManager.Instance._queueTypes;
|
|
28
24
|
}
|
|
@@ -49,7 +45,7 @@ class QueueManager {
|
|
|
49
45
|
}
|
|
50
46
|
async loadQueueTypes(contextUser) {
|
|
51
47
|
// load all of the queue types from the database
|
|
52
|
-
const rv = new
|
|
48
|
+
const rv = new RunView();
|
|
53
49
|
const queueTypes = await rv.RunView({
|
|
54
50
|
EntityName: 'Queue Types',
|
|
55
51
|
}, contextUser);
|
|
@@ -64,7 +60,7 @@ class QueueManager {
|
|
|
64
60
|
if (QueueManager._instance === null) {
|
|
65
61
|
// check the global object first to see if we have an instance there since multiple modules might load this code
|
|
66
62
|
// and the static instance colud be different for each module based on JS import paths
|
|
67
|
-
const g =
|
|
63
|
+
const g = MJGlobal.Instance.GetGlobalObjectStore();
|
|
68
64
|
if (g && g[QueueManager._globalInstanceKey]) {
|
|
69
65
|
QueueManager._instance = g[QueueManager._globalInstanceKey];
|
|
70
66
|
}
|
|
@@ -95,7 +91,7 @@ class QueueManager {
|
|
|
95
91
|
const queue = await this.CheckCreateQueue(queueType, contextUser);
|
|
96
92
|
if (queue) {
|
|
97
93
|
// STEP 3: Create a task in the database for this new task
|
|
98
|
-
const md = new
|
|
94
|
+
const md = new Metadata();
|
|
99
95
|
const taskRecord = await md.GetEntityObject('Queue Tasks', contextUser);
|
|
100
96
|
taskRecord.Set('QueueID', queue.QueueID);
|
|
101
97
|
taskRecord.Set('Status', 'Pending');
|
|
@@ -103,7 +99,7 @@ class QueueManager {
|
|
|
103
99
|
taskRecord.Set('Options', JSON.stringify(options));
|
|
104
100
|
if (await taskRecord.Save()) {
|
|
105
101
|
// db save worked, now we can create a taskBase object
|
|
106
|
-
const task = new
|
|
102
|
+
const task = new TaskBase(taskRecord, data, options);
|
|
107
103
|
queue.AddTask(task);
|
|
108
104
|
return task;
|
|
109
105
|
}
|
|
@@ -112,7 +108,7 @@ class QueueManager {
|
|
|
112
108
|
}
|
|
113
109
|
}
|
|
114
110
|
catch (e) {
|
|
115
|
-
|
|
111
|
+
LogError(e.message);
|
|
116
112
|
}
|
|
117
113
|
}
|
|
118
114
|
async CheckCreateQueue(queueType, contextUser) {
|
|
@@ -139,7 +135,7 @@ class QueueManager {
|
|
|
139
135
|
async CreateQueue(queueType, contextUser) {
|
|
140
136
|
try {
|
|
141
137
|
// create a new queue, based on the Queue Type metadata and process info
|
|
142
|
-
const md = new
|
|
138
|
+
const md = new Metadata();
|
|
143
139
|
const newQueueRecord = await md.GetEntityObject('Queues', contextUser);
|
|
144
140
|
newQueueRecord.NewRecord();
|
|
145
141
|
newQueueRecord.Set('QueueTypeID', queueType.ID);
|
|
@@ -149,7 +145,7 @@ class QueueManager {
|
|
|
149
145
|
newQueueRecord.Set('ProcessPlatform', process.platform);
|
|
150
146
|
newQueueRecord.Set('ProcessVersion', process.version);
|
|
151
147
|
newQueueRecord.Set('ProcessCwd', process.cwd());
|
|
152
|
-
const networkInterfaces =
|
|
148
|
+
const networkInterfaces = os.networkInterfaces();
|
|
153
149
|
const interfaceNames = Object.keys(networkInterfaces);
|
|
154
150
|
if (interfaceNames.length > 0) {
|
|
155
151
|
const firstInterfaceName = interfaceNames[0];
|
|
@@ -159,14 +155,14 @@ class QueueManager {
|
|
|
159
155
|
newQueueRecord.Set('ProcessMacAddress', firstInterface[0].mac);
|
|
160
156
|
}
|
|
161
157
|
}
|
|
162
|
-
newQueueRecord.Set('ProcessOSName',
|
|
163
|
-
newQueueRecord.Set('ProcessOSVersion',
|
|
164
|
-
newQueueRecord.Set('ProcessHostName',
|
|
165
|
-
newQueueRecord.Set('ProcessUserID',
|
|
166
|
-
newQueueRecord.Set('ProcessUserName',
|
|
158
|
+
newQueueRecord.Set('ProcessOSName', os.type());
|
|
159
|
+
newQueueRecord.Set('ProcessOSVersion', os.release());
|
|
160
|
+
newQueueRecord.Set('ProcessHostName', os.hostname());
|
|
161
|
+
newQueueRecord.Set('ProcessUserID', os.userInfo().uid.toString());
|
|
162
|
+
newQueueRecord.Set('ProcessUserName', os.userInfo().username);
|
|
167
163
|
newQueueRecord.Set('LastHeartbeat', new Date());
|
|
168
164
|
if (await newQueueRecord.Save()) {
|
|
169
|
-
const newQueue =
|
|
165
|
+
const newQueue = MJGlobal.Instance.ClassFactory.CreateInstance(QueueBase, queueType.Name, newQueueRecord, queueType.ID, contextUser);
|
|
170
166
|
if (newQueue)
|
|
171
167
|
this._queues.push(newQueue);
|
|
172
168
|
return newQueue;
|
|
@@ -175,7 +171,7 @@ class QueueManager {
|
|
|
175
171
|
throw new Error(`Unable to create new queue for Queue Type ID ${queueType.ID}.`);
|
|
176
172
|
}
|
|
177
173
|
catch (e) {
|
|
178
|
-
|
|
174
|
+
LogError(e.message);
|
|
179
175
|
return null;
|
|
180
176
|
}
|
|
181
177
|
}
|
|
@@ -183,7 +179,4 @@ class QueueManager {
|
|
|
183
179
|
return this._queues;
|
|
184
180
|
}
|
|
185
181
|
}
|
|
186
|
-
exports.QueueManager = QueueManager;
|
|
187
|
-
QueueManager._instance = null;
|
|
188
|
-
QueueManager._globalInstanceKey = '__mj_queue_manager_instance__';
|
|
189
182
|
//# sourceMappingURL=QueueManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../src/generic/QueueManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../src/generic/QueueManager.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAwB,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,YAAY;aAGR,cAAS,GAAwB,IAAI,AAA5B,CAA6B;aACtC,uBAAkB,GAAG,+BAA+B,AAAlC,CAAmC;IAE7D,MAAM,KAAK,UAAU;QAC1B,OAAO,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC;IAC3C,CAAC;IAEM,MAAM,KAAK,QAAQ;QACxB,IAAI,YAAY,CAAC,SAAS,KAAK,IAAI;YACjC,YAAY,CAAC,SAAS,GAAG,IAAI,YAAY,EAAE,CAAC;QAE9C,OAAO,YAAY,CAAC,SAAS,CAAC;IAChC,CAAC;IAGM,KAAK,CAAC,MAAM,CAAC,WAAqB;QACvC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;gBACxB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YACxD,CAAC;YAED,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,aAAa,CAAC;YAC3B,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAqB;QAC9C,MAAM,YAAY,CAAC,QAAQ,CAA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,CAAC;;gBAEC,MAAM,IAAI,KAAK,CAAC,gDAAgD,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;QACrF,CAAC;QACD,OAAO,CAAM,EAAE,CAAC;YACd,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,IAAc,MAAM;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './generic/QueueBase';
|
|
2
|
-
export * from './generic/QueueManager';
|
|
3
|
-
export * from './drivers/AIActionQueue';
|
|
1
|
+
export * from './generic/QueueBase.js';
|
|
2
|
+
export * from './generic/QueueManager.js';
|
|
3
|
+
export * from './drivers/AIActionQueue.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const ai_provider_bundle_1 = require("@memberjunction/ai-provider-bundle");
|
|
18
|
-
(0, ai_provider_bundle_1.LoadAIProviders)(); // Ensure all AI providers are loaded
|
|
19
|
-
__exportStar(require("./generic/QueueBase"), exports);
|
|
20
|
-
__exportStar(require("./generic/QueueManager"), exports);
|
|
21
|
-
__exportStar(require("./drivers/AIActionQueue"), exports);
|
|
1
|
+
export * from './generic/QueueBase.js';
|
|
2
|
+
export * from './generic/QueueManager.js';
|
|
3
|
+
export * from './drivers/AIActionQueue.js';
|
|
22
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/queue",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "4.1.0",
|
|
4
5
|
"description": "MemberJunction: Queue Library for managing server side queues",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,24 +10,24 @@
|
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
12
|
"start": "ts-node-dev src/index.ts",
|
|
12
|
-
"build": "tsc",
|
|
13
|
+
"build": "tsc && tsc-alias -f",
|
|
13
14
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
15
|
},
|
|
15
16
|
"author": "MemberJunction.com",
|
|
16
17
|
"license": "ISC",
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"ts-node-dev": "^2.0.0",
|
|
19
|
-
"typescript": "^5.
|
|
20
|
+
"typescript": "^5.9.3"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@memberjunction/ai": "
|
|
23
|
-
"@memberjunction/ai-provider-bundle": "
|
|
24
|
-
"@memberjunction/aiengine": "
|
|
25
|
-
"@memberjunction/core": "
|
|
26
|
-
"@memberjunction/global": "
|
|
27
|
-
"@memberjunction/core-entities": "
|
|
28
|
-
"@types/uuid": "^
|
|
29
|
-
"uuid": "^
|
|
23
|
+
"@memberjunction/ai": "4.1.0",
|
|
24
|
+
"@memberjunction/ai-provider-bundle": "4.1.0",
|
|
25
|
+
"@memberjunction/aiengine": "4.1.0",
|
|
26
|
+
"@memberjunction/core": "4.1.0",
|
|
27
|
+
"@memberjunction/global": "4.1.0",
|
|
28
|
+
"@memberjunction/core-entities": "4.1.0",
|
|
29
|
+
"@types/uuid": "^11.0.0",
|
|
30
|
+
"uuid": "^13.0.0"
|
|
30
31
|
},
|
|
31
32
|
"repository": {
|
|
32
33
|
"type": "git",
|