s3db.js 11.0.1 → 11.0.3
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/s3db.cjs.js +621 -319
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.es.js +621 -319
- package/dist/s3db.es.js.map +1 -1
- package/package.json +1 -1
- package/src/concerns/plugin-storage.js +274 -9
- package/src/plugins/audit.plugin.js +94 -18
- package/src/plugins/eventual-consistency/analytics.js +136 -20
- package/src/plugins/eventual-consistency/config.js +4 -2
- package/src/plugins/eventual-consistency/consolidation.js +35 -39
- package/src/plugins/eventual-consistency/garbage-collection.js +11 -13
- package/src/plugins/eventual-consistency/index.js +28 -19
- package/src/plugins/eventual-consistency/install.js +9 -26
- package/src/plugins/eventual-consistency/partitions.js +5 -0
- package/src/plugins/eventual-consistency/transactions.js +1 -0
- package/src/plugins/eventual-consistency/utils.js +36 -1
- package/src/plugins/fulltext.plugin.js +76 -22
- package/src/plugins/metrics.plugin.js +70 -20
- package/src/plugins/s3-queue.plugin.js +21 -120
- package/src/plugins/scheduler.plugin.js +11 -37
- package/dist/s3db-cli.js +0 -54741
|
@@ -163,7 +163,6 @@ export class SchedulerPlugin extends Plugin {
|
|
|
163
163
|
};
|
|
164
164
|
|
|
165
165
|
this.database = null;
|
|
166
|
-
this.lockResource = null;
|
|
167
166
|
this.jobs = new Map();
|
|
168
167
|
this.activeJobs = new Map();
|
|
169
168
|
this.timers = new Map();
|
|
@@ -218,9 +217,7 @@ export class SchedulerPlugin extends Plugin {
|
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
async onInstall() {
|
|
221
|
-
|
|
222
|
-
// Create lock resource for distributed locking
|
|
223
|
-
await this._createLockResource();
|
|
220
|
+
// Locks are now managed by PluginStorage with TTL - no Resource needed
|
|
224
221
|
|
|
225
222
|
// Create job execution history resource
|
|
226
223
|
if (this.config.persistJobs) {
|
|
@@ -258,27 +255,6 @@ export class SchedulerPlugin extends Plugin {
|
|
|
258
255
|
this.emit('initialized', { jobs: this.jobs.size });
|
|
259
256
|
}
|
|
260
257
|
|
|
261
|
-
async _createLockResource() {
|
|
262
|
-
const [ok, err, lockResource] = await tryFn(() =>
|
|
263
|
-
this.database.createResource({
|
|
264
|
-
name: 'plg_scheduler_job_locks',
|
|
265
|
-
attributes: {
|
|
266
|
-
id: 'string|required',
|
|
267
|
-
jobName: 'string|required',
|
|
268
|
-
lockedAt: 'number|required',
|
|
269
|
-
instanceId: 'string|optional'
|
|
270
|
-
},
|
|
271
|
-
behavior: 'body-only',
|
|
272
|
-
timestamps: false
|
|
273
|
-
})
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
if (!ok && !this.database.resources.plg_scheduler_job_locks) {
|
|
277
|
-
throw new Error(`Failed to create lock resource: ${err?.message}`);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
this.lockResource = ok ? lockResource : this.database.resources.plg_scheduler_job_locks;
|
|
281
|
-
}
|
|
282
258
|
|
|
283
259
|
async _createJobHistoryResource() {
|
|
284
260
|
const [ok] = await tryFn(() => this.database.createResource({
|
|
@@ -416,19 +392,17 @@ export class SchedulerPlugin extends Plugin {
|
|
|
416
392
|
// Mark as active immediately (will be updated with executionId later)
|
|
417
393
|
this.activeJobs.set(jobName, 'acquiring-lock');
|
|
418
394
|
|
|
419
|
-
// Acquire distributed lock to prevent concurrent execution across instances
|
|
420
|
-
const
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
})
|
|
428
|
-
);
|
|
395
|
+
// Acquire distributed lock with TTL to prevent concurrent execution across instances
|
|
396
|
+
const storage = this.getStorage();
|
|
397
|
+
const lockKey = `job-${jobName}`;
|
|
398
|
+
const lock = await storage.acquireLock(lockKey, {
|
|
399
|
+
ttl: Math.ceil(job.timeout / 1000) + 60, // Job timeout + 60 seconds buffer
|
|
400
|
+
timeout: 0, // Don't wait if locked
|
|
401
|
+
workerId: process.pid ? String(process.pid) : 'unknown'
|
|
402
|
+
});
|
|
429
403
|
|
|
430
404
|
// If lock couldn't be acquired, another instance is executing this job
|
|
431
|
-
if (!
|
|
405
|
+
if (!lock) {
|
|
432
406
|
if (this.config.verbose) {
|
|
433
407
|
console.log(`[SchedulerPlugin] Job '${jobName}' already running on another instance`);
|
|
434
408
|
}
|
|
@@ -577,7 +551,7 @@ export class SchedulerPlugin extends Plugin {
|
|
|
577
551
|
}
|
|
578
552
|
} finally {
|
|
579
553
|
// Always release the distributed lock
|
|
580
|
-
await tryFn(() =>
|
|
554
|
+
await tryFn(() => storage.releaseLock(lockKey));
|
|
581
555
|
}
|
|
582
556
|
}
|
|
583
557
|
|