Skip to content

Commit 2632872

Browse files
committed
refactor task protection
1 parent 71c7a0d commit 2632872

3 files changed

Lines changed: 590 additions & 326 deletions

File tree

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,10 @@ const queue = new SQSQueue({
378378
queueUrl: process.env.SQS_QUEUE_URL!,
379379
name: 'email-queue',
380380
onFailure: 'delete', // or 'leaveInQueue'
381-
plugins: [ecsTaskProtection(protectionManager)]
381+
plugins: [ecsTaskProtection({
382+
manager: protectionManager,
383+
defaultProtectionTimeout: 600 // 10 minutes default
384+
})]
382385
});
383386

384387
await queue.run(true, 3);
@@ -388,9 +391,10 @@ await protectionManager.cleanup();
388391
```
389392

390393
**Features:**
391-
- **Automatic Protection**: Acquires ECS task protection when jobs are active, releases when idle
392-
- **Draining Detection**: Detects when ECS is draining and gracefully stops accepting new jobs
393-
- **Auto-Renewal**: Refreshes protection before expiration for long-running jobs
394+
- **Smart Protection Management**: Acquires protection before polling, maintains it while jobs are active
395+
- **Reference Counting**: Tracks active jobs per queue, only releases protection when all jobs complete
396+
- **TTR-Aware**: Automatically extends protection for long-running jobs based on their TTR
397+
- **Draining Detection**: Detects when ECS is draining and gracefully stops accepting new jobs
394398
- **Zero Dependencies**: Uses built-in Node.js `fetch` API
395399
- **Configurable Logging**: Integrate with your existing logging system
396400

@@ -418,15 +422,15 @@ const emailQueue = new SQSQueue({
418422
queueUrl: process.env.EMAIL_QUEUE_URL!,
419423
name: 'email-queue',
420424
onFailure: 'delete',
421-
plugins: [ecsTaskProtection(protectionManager)]
425+
plugins: [ecsTaskProtection({ manager: protectionManager })]
422426
});
423427

424428
const imageQueue = new SQSQueue({
425429
client: new SQSClient({ region: 'us-east-1' }),
426430
queueUrl: process.env.IMAGE_QUEUE_URL!,
427431
name: 'image-queue',
428432
onFailure: 'delete',
429-
plugins: [ecsTaskProtection(protectionManager)] // Same instance
433+
plugins: [ecsTaskProtection({ manager: protectionManager })] // Same manager, different plugin instance
430434
});
431435

432436
// Both queues coordinate protection through the shared manager

0 commit comments

Comments
 (0)