@cloudnux/local-cloud-provider 0.7.0 → 0.10.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/dist/dev-console-plugin/index.d.ts +0 -2
- package/dist/dev-console-plugin/index.js +82 -52
- package/dist/dev-console-plugin/index.js.map +1 -1
- package/dist/index.js +38 -1
- package/dist/index.js.map +1 -1
- package/dist/queue-plugin/index.d.ts +1 -2
- package/dist/queue-plugin/index.js +38 -17
- package/dist/queue-plugin/index.js.map +1 -1
- package/dist/schedule-plugin/index.d.ts +3 -1
- package/dist/schedule-plugin/index.js +44 -35
- package/dist/schedule-plugin/index.js.map +1 -1
- package/dist/websocket-plugin/index.d.ts +43 -0
- package/dist/websocket-plugin/index.js +96 -0
- package/dist/websocket-plugin/index.js.map +1 -0
- package/package.json +10 -3
|
@@ -20,7 +20,6 @@ interface QueueService {
|
|
|
20
20
|
dlq: QueueMessage[];
|
|
21
21
|
timeoutId: NodeJS.Timeout | null;
|
|
22
22
|
processingBatch: boolean;
|
|
23
|
-
activeProcessing: number;
|
|
24
23
|
module?: string;
|
|
25
24
|
}
|
|
26
25
|
interface QueueConfig {
|
|
@@ -43,7 +42,6 @@ interface QueueSummary {
|
|
|
43
42
|
processing: number;
|
|
44
43
|
dlq: number;
|
|
45
44
|
isProcessing: boolean;
|
|
46
|
-
activeProcessing: number;
|
|
47
45
|
configuration: {
|
|
48
46
|
batchSize: number;
|
|
49
47
|
batchWindowMs: number;
|
|
@@ -94,6 +92,7 @@ interface QueueManager {
|
|
|
94
92
|
interface QueueDecoratorOptions {
|
|
95
93
|
config: QueueConfig;
|
|
96
94
|
queues: Record<string, QueueService>;
|
|
95
|
+
dirtyQueues: Set<string>;
|
|
97
96
|
saveQueueState?: (queueName: string, queueService: QueueService) => Promise<void>;
|
|
98
97
|
loadQueueState?: (queueName: string) => Promise<void>;
|
|
99
98
|
scheduleProcessing: (queueName: string, queueService: QueueService) => void;
|
|
@@ -950,7 +950,6 @@ var createQueueService = (handler, module) => ({
|
|
|
950
950
|
dlq: [],
|
|
951
951
|
timeoutId: null,
|
|
952
952
|
processingBatch: false,
|
|
953
|
-
activeProcessing: 0,
|
|
954
953
|
module
|
|
955
954
|
});
|
|
956
955
|
var createQueueMessage = (body, headers) => {
|
|
@@ -997,7 +996,6 @@ var createQueueSummary = (queueService, config) => ({
|
|
|
997
996
|
processing: queueService.processing.length,
|
|
998
997
|
dlq: queueService.dlq.length,
|
|
999
998
|
isProcessing: queueService.processingBatch,
|
|
1000
|
-
activeProcessing: queueService.activeProcessing,
|
|
1001
999
|
configuration: {
|
|
1002
1000
|
batchSize: config.batchSize,
|
|
1003
1001
|
batchWindowMs: config.batchWindowMs,
|
|
@@ -1039,7 +1037,7 @@ var logError = (message, messageId, queueName, error) => {
|
|
|
1039
1037
|
logger.error(`${logSymbols.error} ${chalk2.red(message)} ${chalk2.yellow(messageId)} in queue ${chalk2.magenta(queueName)}: ${error}`);
|
|
1040
1038
|
};
|
|
1041
1039
|
var logRetryScheduled = (messageId, delayMs) => {
|
|
1042
|
-
logger.
|
|
1040
|
+
logger.debug(`${chalk2.blue("\u23F1\uFE0F Scheduling retry")} for message ${chalk2.yellow(messageId)} in ${chalk2.cyan(delayMs)}ms`);
|
|
1043
1041
|
};
|
|
1044
1042
|
var logDLQOperation = (operation, count, queueName) => {
|
|
1045
1043
|
logger.warn(`${logSymbols.warning} ${chalk2.yellow(operation)} ${chalk2.red(count)} messages from DLQ for ${chalk2.green(queueName)}`);
|
|
@@ -1072,7 +1070,7 @@ var handleProcessingError = async (queueName, message, queueService, error, conf
|
|
|
1072
1070
|
}, delayMs);
|
|
1073
1071
|
}
|
|
1074
1072
|
};
|
|
1075
|
-
var createBatchProcessor = (processMessage, config,
|
|
1073
|
+
var createBatchProcessor = (processMessage, config, dirtyQueues) => async (queueName, queueService) => {
|
|
1076
1074
|
if (queueService.timeoutId) {
|
|
1077
1075
|
clearTimeout(queueService.timeoutId);
|
|
1078
1076
|
queueService.timeoutId = null;
|
|
@@ -1090,8 +1088,8 @@ var createBatchProcessor = (processMessage, config, saveQueueState) => async (qu
|
|
|
1090
1088
|
await Promise.all(messagesToProcess.map((message) => {
|
|
1091
1089
|
return processMessage(queueName, message, queueService);
|
|
1092
1090
|
}));
|
|
1093
|
-
if (config.persistence.enabled &&
|
|
1094
|
-
|
|
1091
|
+
if (config.persistence.enabled && dirtyQueues) {
|
|
1092
|
+
dirtyQueues.add(queueName);
|
|
1095
1093
|
}
|
|
1096
1094
|
} finally {
|
|
1097
1095
|
queueService.processingBatch = false;
|
|
@@ -1133,18 +1131,21 @@ var restoreDates = (messages) => {
|
|
|
1133
1131
|
if (msg.failedAt) msg.failedAt = new Date(msg.failedAt);
|
|
1134
1132
|
});
|
|
1135
1133
|
};
|
|
1136
|
-
var createPersistenceInitializer = (config, loadAllQueueStates, saveAllQueueStates) => async () => {
|
|
1134
|
+
var createPersistenceInitializer = (config, loadAllQueueStates, saveDirtyQueueStates, saveAllQueueStates, intervalIdHolder) => async () => {
|
|
1137
1135
|
try {
|
|
1138
1136
|
await fs.mkdir(config.persistence.directory, { recursive: true });
|
|
1139
1137
|
if (config.persistence.loadOnStartup) {
|
|
1140
1138
|
await loadAllQueueStates();
|
|
1141
1139
|
}
|
|
1142
1140
|
if (config.persistence.saveInterval > 0) {
|
|
1143
|
-
setInterval(
|
|
1141
|
+
intervalIdHolder.id = setInterval(saveDirtyQueueStates, config.persistence.saveInterval);
|
|
1144
1142
|
}
|
|
1145
1143
|
if (config.persistence.saveOnShutdown) {
|
|
1146
1144
|
const shutdownHandler = async () => {
|
|
1147
1145
|
logger.debug("Saving queue state before shutdown...");
|
|
1146
|
+
if (intervalIdHolder.id) {
|
|
1147
|
+
clearInterval(intervalIdHolder.id);
|
|
1148
|
+
}
|
|
1148
1149
|
await saveAllQueueStates();
|
|
1149
1150
|
process.exit(0);
|
|
1150
1151
|
};
|
|
@@ -1165,7 +1166,7 @@ var createQueueStateSaver = (config) => async (queueName, queueService) => {
|
|
|
1165
1166
|
const tempFilePath = path.join(config.persistence.directory, `${queueName}.${now}temp.json`);
|
|
1166
1167
|
await fs.writeFile(tempFilePath, JSON.stringify(queueData, null, 2), "utf8");
|
|
1167
1168
|
await fs.rename(tempFilePath, queueFilePath);
|
|
1168
|
-
logger.
|
|
1169
|
+
logger.debug(`${logSymbols2.info} ${chalk3.blue("Queue state saved:")} ${chalk3.green(queueName)}`);
|
|
1169
1170
|
} catch (error) {
|
|
1170
1171
|
logger.error(`Failed to save queue state for ${queueName}:`, error);
|
|
1171
1172
|
}
|
|
@@ -1180,6 +1181,20 @@ var createAllQueuesStateSaver = (config, saveQueueState) => (queues) => async ()
|
|
|
1180
1181
|
logger.error(`${logSymbols2.error} ${chalk3.red("Failed to save all queue states:")} ${chalk3.yellow(error.message)}`);
|
|
1181
1182
|
}
|
|
1182
1183
|
};
|
|
1184
|
+
var createDirtyQueuesStateSaver = (saveQueueState, dirtyQueues) => (queues) => async () => {
|
|
1185
|
+
if (dirtyQueues.size === 0) return;
|
|
1186
|
+
try {
|
|
1187
|
+
const queueNames = [...dirtyQueues];
|
|
1188
|
+
dirtyQueues.clear();
|
|
1189
|
+
for (const queueName of queueNames) {
|
|
1190
|
+
if (queues[queueName]) {
|
|
1191
|
+
await saveQueueState(queueName, queues[queueName]);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
} catch (error) {
|
|
1195
|
+
logger.error(`${logSymbols2.error} ${chalk3.red("Failed to save dirty queue states:")} ${chalk3.yellow(error.message)}`);
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1183
1198
|
var createQueueStateLoader = (config, scheduleProcessing, processMessage) => (queues) => async (queueName) => {
|
|
1184
1199
|
try {
|
|
1185
1200
|
if (!queues[queueName]) {
|
|
@@ -1297,6 +1312,7 @@ var isValidQueueName = (queueName) => {
|
|
|
1297
1312
|
var createQueueManager = ({
|
|
1298
1313
|
config,
|
|
1299
1314
|
queues,
|
|
1315
|
+
dirtyQueues,
|
|
1300
1316
|
saveQueueState,
|
|
1301
1317
|
loadQueueState,
|
|
1302
1318
|
scheduleProcessing,
|
|
@@ -1407,8 +1423,8 @@ var createQueueManager = ({
|
|
|
1407
1423
|
queues[queueName].incoming.push(message);
|
|
1408
1424
|
scheduleProcessing(queueName, queues[queueName]);
|
|
1409
1425
|
handleImmediateProcessing(queues[queueName], config, processBatch, queueName);
|
|
1410
|
-
if (config.persistence.enabled
|
|
1411
|
-
|
|
1426
|
+
if (config.persistence.enabled) {
|
|
1427
|
+
dirtyQueues.add(queueName);
|
|
1412
1428
|
}
|
|
1413
1429
|
return {
|
|
1414
1430
|
id: message.id,
|
|
@@ -1429,8 +1445,8 @@ var createQueueManager = ({
|
|
|
1429
1445
|
}
|
|
1430
1446
|
logDLQOperation("Moving", processedCount, queueName);
|
|
1431
1447
|
scheduleProcessing(queueName, queues[queueName]);
|
|
1432
|
-
if (
|
|
1433
|
-
|
|
1448
|
+
if (config.persistence.enabled) {
|
|
1449
|
+
dirtyQueues.add(queueName);
|
|
1434
1450
|
}
|
|
1435
1451
|
return {
|
|
1436
1452
|
status: "success",
|
|
@@ -1451,8 +1467,8 @@ var createQueueManager = ({
|
|
|
1451
1467
|
};
|
|
1452
1468
|
}
|
|
1453
1469
|
logDLQOperation("Purging", purgedCount, queueName);
|
|
1454
|
-
if (
|
|
1455
|
-
|
|
1470
|
+
if (config.persistence.enabled) {
|
|
1471
|
+
dirtyQueues.add(queueName);
|
|
1456
1472
|
}
|
|
1457
1473
|
return {
|
|
1458
1474
|
status: "success",
|
|
@@ -1483,14 +1499,18 @@ var createQueueDecorator = (queueManager) => (app) => {
|
|
|
1483
1499
|
var queuesPlugin = fsPlugin(async (app, options) => {
|
|
1484
1500
|
const config = mergeConfig(DEFAULT_CONFIG, options.config);
|
|
1485
1501
|
const queues = {};
|
|
1502
|
+
const dirtyQueues = /* @__PURE__ */ new Set();
|
|
1503
|
+
const intervalIdHolder = {};
|
|
1486
1504
|
const processMessage = createProcessMessageHandler(config);
|
|
1487
1505
|
const saveQueueState = config.persistence.enabled ? createQueueStateSaver(config) : void 0;
|
|
1488
1506
|
const saveAllQueueStates = config.persistence.enabled && saveQueueState ? createAllQueuesStateSaver(config, saveQueueState)(queues) : async () => {
|
|
1489
1507
|
};
|
|
1508
|
+
const saveDirtyQueueStates = config.persistence.enabled && saveQueueState ? createDirtyQueuesStateSaver(saveQueueState, dirtyQueues)(queues) : async () => {
|
|
1509
|
+
};
|
|
1490
1510
|
const processBatch = createBatchProcessor(
|
|
1491
1511
|
processMessage,
|
|
1492
1512
|
config,
|
|
1493
|
-
|
|
1513
|
+
config.persistence.enabled ? dirtyQueues : void 0
|
|
1494
1514
|
);
|
|
1495
1515
|
const scheduleProcessing = createProcessingScheduler(processBatch, config);
|
|
1496
1516
|
const loadQueueState = config.persistence.enabled ? createQueueStateLoader(
|
|
@@ -1501,11 +1521,12 @@ var queuesPlugin = fsPlugin(async (app, options) => {
|
|
|
1501
1521
|
};
|
|
1502
1522
|
const loadAllQueueStates = config.persistence.enabled ? createAllQueuesStateLoader(config, loadQueueState) : async () => {
|
|
1503
1523
|
};
|
|
1504
|
-
const initializePersistence = config.persistence.enabled ? createPersistenceInitializer(config, loadAllQueueStates, saveAllQueueStates) : async () => {
|
|
1524
|
+
const initializePersistence = config.persistence.enabled ? createPersistenceInitializer(config, loadAllQueueStates, saveDirtyQueueStates, saveAllQueueStates, intervalIdHolder) : async () => {
|
|
1505
1525
|
};
|
|
1506
1526
|
const queueManager = createQueueManager({
|
|
1507
1527
|
config,
|
|
1508
1528
|
queues,
|
|
1529
|
+
dirtyQueues,
|
|
1509
1530
|
saveQueueState: saveQueueState ? (queueName) => saveQueueState(queueName, queues[queueName]) : void 0,
|
|
1510
1531
|
loadQueueState,
|
|
1511
1532
|
scheduleProcessing,
|