@friggframework/core 2.0.0--canary.657.798cee9.0 → 2.0.0--canary.656.602fc50.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/CLAUDE.md +7 -81
- package/core/CLAUDE.md +0 -30
- package/core/Worker.js +9 -316
- package/errors/rate-limit-error.js +1 -0
- package/handlers/backend-utils.js +1 -30
- package/infrastructure/scheduler/eventbridge-scheduler-adapter.js +0 -2
- package/integrations/use-cases/index.js +1 -5
- package/modules/requester/oauth-2.js +0 -7
- package/modules/requester/rate-limit/policy.js +3 -3
- package/package.json +5 -7
- package/queues/queue-delivery.js +0 -1
- package/queues/queuer-util.js +1 -1
- package/types/core/index.d.ts +0 -19
- package/integrations/use-cases/clear-rate-limit-wait.js +0 -28
- package/integrations/use-cases/record-rate-limit-wait.js +0 -36
- package/queues/queue-deferral.js +0 -74
package/CLAUDE.md
CHANGED
|
@@ -486,22 +486,20 @@ handlers (`{ req, res, next }`) and `this.on` events do not.
|
|
|
486
486
|
|
|
487
487
|
`isLastAttempt` is `false` when either count is unknown: a local or non-SQS
|
|
488
488
|
invocation, or a queue whose redrive policy the stack does not own
|
|
489
|
-
(`ownership.queue: 'external'`). The value
|
|
490
|
-
retryable
|
|
491
|
-
to run at `retryAt` (see **Rate-limit deferral** below), and a halt error (4xx
|
|
492
|
-
except 408, 429 and errors with `isRateLimited`) discards it.
|
|
489
|
+
(`ownership.queue: 'external'`). The value is information only: core still
|
|
490
|
+
rethrows retryable errors and discards halt errors (4xx except 408 and 429).
|
|
493
491
|
|
|
494
|
-
Use it to end a run or count lost work on the final try
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
492
|
+
Use it to end a run or count lost work on the final try: when a retryable
|
|
493
|
+
error (429, 5xx, network) is about to be rethrown and `isLastAttempt` is
|
|
494
|
+
`true`, the message goes to the DLQ next, so mark the run failed or count the
|
|
495
|
+
message's records as failed before rethrowing.
|
|
498
496
|
|
|
499
497
|
```javascript
|
|
500
498
|
async processBatch({ data, delivery }) {
|
|
501
499
|
try {
|
|
502
500
|
await this.syncPage(data);
|
|
503
501
|
} catch (error) {
|
|
504
|
-
if (delivery?.isLastAttempt)
|
|
502
|
+
if (delivery?.isLastAttempt) await this.failRun(data.processId, error);
|
|
505
503
|
throw error;
|
|
506
504
|
}
|
|
507
505
|
}
|
|
@@ -512,76 +510,6 @@ The single source of the max receive count is
|
|
|
512
510
|
devtools integration builder uses it for the queue's `RedrivePolicy` and sets
|
|
513
511
|
it as `FRIGG_QUEUE_MAX_RECEIVE_COUNT` on the queue worker function.
|
|
514
512
|
|
|
515
|
-
**Rate-limit deferral** (ADR-049): when a queue handler throws an error with
|
|
516
|
-
`isRateLimited` and a `retryAt` (a `RateLimitError` from the Requester, or one a
|
|
517
|
-
module throws), `Worker.run` does not give the message back to SQS for a 30
|
|
518
|
-
minute redelivery. It puts the message back so it runs at `retryAt`:
|
|
519
|
-
|
|
520
|
-
| Wait | What the worker does | Record |
|
|
521
|
-
|---|---|---|
|
|
522
|
-
| Up to 900 s | Sends the same body again with `DelaySeconds`, then acknowledges the old message | handled |
|
|
523
|
-
| Over 900 s, and `SCHEDULER_ROLE_ARN` is set | Creates a one-time EventBridge schedule at `retryAt` that sends the body to the queue, then acknowledges | handled |
|
|
524
|
-
| Over 900 s, no scheduler | Extends the message's visibility timeout to `retryAt` (12 h less 20 minutes at most). This uses one receive | reported failed |
|
|
525
|
-
|
|
526
|
-
- The new message starts at receive count 1. A deferred body carries
|
|
527
|
-
`_frigg: { deferrals, firstDeferredAt, deferralId }`; `_frigg` is reserved and
|
|
528
|
-
the handler never sees it. `deferralId` is the SQS message id of the first
|
|
529
|
-
message that was put back, and every later deferral of that work keeps it.
|
|
530
|
-
- The visibility tier sets a timeout of at most 12 h less 20 minutes
|
|
531
|
-
(42,000 s). SQS counts its 12 h maximum from the receive, and an extension
|
|
532
|
-
does not reset it. The margin covers the longest Lambda run (900 s) plus the
|
|
533
|
-
longest batching window (300 s).
|
|
534
|
-
- Two caps bound it: `FRIGG_QUEUE_MAX_DEFERRALS` (default 30) and
|
|
535
|
-
`FRIGG_QUEUE_MAX_DEFERRED_MS` (default 26 h, from the first deferral to the
|
|
536
|
-
retry time). The defaults cover one full day of hourly waits, for a module
|
|
537
|
-
that probes a daily limit every hour. Past a cap, with no `retryAt`, with no
|
|
538
|
-
event source ARN or on a FIFO queue, the record fails like any retryable
|
|
539
|
-
error and `delivery` applies.
|
|
540
|
-
- The mock scheduler is never used for a deferral: a schedule kept in memory
|
|
541
|
-
would be lost with the acknowledged message.
|
|
542
|
-
- With a `processId` in the message, the worker writes
|
|
543
|
-
`Process.context.rateLimit = { status: 'WAITING' | 'EXHAUSTED', mechanism,
|
|
544
|
-
retryAt, reason, module, deferrals, deferralId, updatedAt }`. `EXHAUSTED` means
|
|
545
|
-
a cap ended the deferrals, or a visibility change came on the last delivery.
|
|
546
|
-
The value is one per process, so it holds the latest known wait: a new wait
|
|
547
|
-
replaces it only when its `retryAt` is later, and a `WAITING` value never hides
|
|
548
|
-
an `EXHAUSTED` one. After a deferred or redelivered message ran, the worker
|
|
549
|
-
sets a `WAITING` value to `null` at once when that message set it (same
|
|
550
|
-
`deferralId`, or the message's own id for a visibility change), and for any
|
|
551
|
-
other message only when its `retryAt` is past or within 5 s. So a job that
|
|
552
|
-
resumes before its `retryAt` clears its own wait, and cannot clear the wait of
|
|
553
|
-
another message.
|
|
554
|
-
- Delivery stays at least once. The new message is sent before the old one is
|
|
555
|
-
acknowledged, so a crash between the two can run the work twice.
|
|
556
|
-
- Handlers check `delivery.isLastAttempt` first, then rethrow. The delay and
|
|
557
|
-
schedule tiers send a new message, so they never reach the last attempt. The
|
|
558
|
-
visibility tier and a cap use a receive: on the last one the worker writes an
|
|
559
|
-
ERROR (`frigg.worker.record_lost_rate_limited`), and the handler has this one
|
|
560
|
-
chance to end the run.
|
|
561
|
-
|
|
562
|
-
```javascript
|
|
563
|
-
async processBatch({ data, delivery }) {
|
|
564
|
-
try {
|
|
565
|
-
await this.syncPage(data);
|
|
566
|
-
} catch (error) {
|
|
567
|
-
if (delivery?.isLastAttempt) return this.failRun(data.processId, error);
|
|
568
|
-
throw error; // a RateLimitError too: core puts the message back at retryAt
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
Records: a rate-limited SQS record gets one log record, by its outcome.
|
|
574
|
-
|
|
575
|
-
| Outcome | Log record |
|
|
576
|
-
|---|---|
|
|
577
|
-
| Acknowledged | WARN `frigg.worker.record_deferred` (`mechanism` `delay` or `schedule`) |
|
|
578
|
-
| Not acknowledged, not the last attempt | One WARN: `record_deferral_capped`, `record_visibility_extended`, or `record_failed` with `deferral.skipped` |
|
|
579
|
-
| Not acknowledged, last attempt | One ERROR, `record_lost_rate_limited`, with the details, and no WARN |
|
|
580
|
-
|
|
581
|
-
A failing run state hook adds `rate_limit_state_failed`. A queue in a stack
|
|
582
|
-
that does not own it (`ownership.queue: 'external'`) needs its own
|
|
583
|
-
`sqs:ChangeMessageVisibility` and scheduler access.
|
|
584
|
-
|
|
585
513
|
### 8. Error Handling (`/errors`)
|
|
586
514
|
|
|
587
515
|
**Purpose**: Standardized error types with proper HTTP semantics.
|
|
@@ -833,8 +761,6 @@ Use test doubles from `@friggframework/test` package for consistent mocking.
|
|
|
833
761
|
- `SECRET_ARN` - AWS Secrets Manager ARN for auto-injection
|
|
834
762
|
- `FRIGG_LOG_LEVEL` - Minimum log level (`TRACE` … `FATAL`, default `INFO`; `DEBUG` on local runs)
|
|
835
763
|
- `FRIGG_QUEUE_MAX_RECEIVE_COUNT` - Set by devtools on integration queue workers whose queue the stack owns; feeds `delivery.maxReceiveCount`
|
|
836
|
-
- `FRIGG_QUEUE_MAX_DEFERRALS` - Most rate-limit deferrals of one message (default 30)
|
|
837
|
-
- `FRIGG_QUEUE_MAX_DEFERRED_MS` - Most time in ms from a message's first rate-limit deferral to its retry time (default 26 h)
|
|
838
764
|
|
|
839
765
|
## Version Information
|
|
840
766
|
|
package/core/CLAUDE.md
CHANGED
|
@@ -79,36 +79,6 @@ await worker.send({
|
|
|
79
79
|
}, delaySeconds);
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
**Rate-limit deferral** (ADR-049): `run()` handles an error with `isRateLimited`
|
|
83
|
-
and a `retryAt` through `defer(record, body, error, delivery)`, which returns
|
|
84
|
-
`{ outcome }`:
|
|
85
|
-
- `acked`: the message was sent again with `DelaySeconds` (wait up to 900 s) or
|
|
86
|
-
scheduled with the one-time scheduler (longer wait). The record is handled.
|
|
87
|
-
- `failed`: the visibility timeout was extended to `retryAt`, or a cap
|
|
88
|
-
(`FRIGG_QUEUE_MAX_DEFERRALS`, `FRIGG_QUEUE_MAX_DEFERRED_MS`) ended the
|
|
89
|
-
deferrals. The record is reported failed.
|
|
90
|
-
- `skipped`: no `retryAt` (`no_retry_at`), no `eventSourceARN` or a FIFO queue
|
|
91
|
-
(`no_event_source`), a failed send (`send_failed`), or a failed visibility
|
|
92
|
-
change (`visibility_failed`). The record fails as any error does.
|
|
93
|
-
|
|
94
|
-
Each outcome writes one log record. `acked` writes WARN `record_deferred`.
|
|
95
|
-
`failed` and `skipped` write one WARN (`record_visibility_extended`,
|
|
96
|
-
`record_deferral_capped`, or `record_failed` with `deferral: { skipped }`). On
|
|
97
|
-
the last attempt they write one ERROR, `record_lost_rate_limited`, with the
|
|
98
|
-
details, and no WARN.
|
|
99
|
-
|
|
100
|
-
Subclasses override two no-op hooks to keep run state.
|
|
101
|
-
`recordRateLimitWait(body, error, state)` runs before a delayed message is sent,
|
|
102
|
-
because with a short delay the new message can run first; a failed send clears
|
|
103
|
-
the wait again. For a schedule or a visibility change it runs after the change.
|
|
104
|
-
`clearRateLimitWait(body, { deferralId })` runs after a deferred or redelivered
|
|
105
|
-
message succeeded.
|
|
106
|
-
`state.deferralId` and `deferralId` name the message that was first put back
|
|
107
|
-
(`_frigg.deferralId`, or the message's own id). A failing hook logs
|
|
108
|
-
`frigg.worker.rate_limit_state_failed` and never changes the outcome. The queue
|
|
109
|
-
worker of an integration (`createQueueWorker`) writes `Process.context.rateLimit`
|
|
110
|
-
in them. See `packages/core/CLAUDE.md` section 7.
|
|
111
|
-
|
|
112
82
|
### Delegate Pattern System (`Delegate.js:3-27`)
|
|
113
83
|
|
|
114
84
|
**Purpose**: Observer/delegation pattern for decoupled component communication
|
package/core/Worker.js
CHANGED
|
@@ -1,38 +1,14 @@
|
|
|
1
|
-
const {
|
|
2
|
-
SQSClient,
|
|
3
|
-
GetQueueUrlCommand,
|
|
4
|
-
SendMessageCommand,
|
|
5
|
-
ChangeMessageVisibilityCommand,
|
|
6
|
-
} = require('@aws-sdk/client-sqs');
|
|
1
|
+
const { SQSClient, GetQueueUrlCommand, SendMessageCommand } = require('@aws-sdk/client-sqs');
|
|
7
2
|
const _ = require('lodash');
|
|
8
3
|
const { RequiredPropertyError } = require('../errors');
|
|
9
4
|
const { get } = require('../assertions');
|
|
10
5
|
const { readQueueDelivery } = require('../queues/queue-delivery');
|
|
11
|
-
const { awsConfigOptions } = require('../queues/queuer-util');
|
|
12
|
-
const {
|
|
13
|
-
MAX_DEFERRED_VISIBILITY_SECONDS,
|
|
14
|
-
MAX_DELAY_SECONDS,
|
|
15
|
-
deferredMs,
|
|
16
|
-
isDeferralCapped,
|
|
17
|
-
nextDeferral,
|
|
18
|
-
readDeferral,
|
|
19
|
-
readDeferralLimits,
|
|
20
|
-
withDeferral,
|
|
21
|
-
} = require('../queues/queue-deferral');
|
|
22
6
|
const { runMessageScope } = require('./invocation-scope');
|
|
23
7
|
const { getLogger } = require('../logs');
|
|
24
8
|
|
|
25
|
-
const sqs = new SQSClient({
|
|
26
|
-
region: process.env.AWS_REGION,
|
|
27
|
-
...awsConfigOptions(),
|
|
28
|
-
});
|
|
9
|
+
const sqs = new SQSClient({ region: process.env.AWS_REGION });
|
|
29
10
|
const log = getLogger('frigg.worker');
|
|
30
11
|
|
|
31
|
-
const validDate = (value) =>
|
|
32
|
-
value instanceof Date && !Number.isNaN(value.getTime()) ? value : null;
|
|
33
|
-
const queueNameOf = (arn) =>
|
|
34
|
-
typeof arn === 'string' && arn ? arn.split(':').pop() : undefined;
|
|
35
|
-
|
|
36
12
|
class Worker {
|
|
37
13
|
async getQueueURL(params) {
|
|
38
14
|
// Passing params in because there will be multiple QueueNames
|
|
@@ -57,31 +33,12 @@ class Worker {
|
|
|
57
33
|
// messageId, receiveCount and the event come from the scope.
|
|
58
34
|
log.debug('Record started', { eventName: 'frigg.worker.record_started' });
|
|
59
35
|
|
|
60
|
-
const delivery = readQueueDelivery(record);
|
|
61
|
-
let runParams;
|
|
62
36
|
try {
|
|
63
|
-
runParams = JSON.parse(record.body);
|
|
37
|
+
const runParams = JSON.parse(record.body);
|
|
64
38
|
this._validateParams(runParams);
|
|
65
|
-
await this._run(runParams, context,
|
|
66
|
-
await this._clearDeferredState(record, runParams, delivery);
|
|
39
|
+
await this._run(runParams, context, readQueueDelivery(record));
|
|
67
40
|
log.debug('Record succeeded', { eventName: 'frigg.worker.record_succeeded' });
|
|
68
41
|
} catch (error) {
|
|
69
|
-
let deferralResult;
|
|
70
|
-
if (error.isRateLimited && runParams) {
|
|
71
|
-
deferralResult = await this.defer(
|
|
72
|
-
record,
|
|
73
|
-
runParams,
|
|
74
|
-
error,
|
|
75
|
-
delivery
|
|
76
|
-
);
|
|
77
|
-
if (deferralResult.outcome === 'acked') return;
|
|
78
|
-
if (deferralResult.outcome === 'failed') {
|
|
79
|
-
batchItemFailures.push({
|
|
80
|
-
itemIdentifier: record.messageId,
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
42
|
if (error.isHaltError) {
|
|
86
43
|
// HaltError means "discard this message, don't retry".
|
|
87
44
|
// Treat as success so SQS deletes it from the queue.
|
|
@@ -94,30 +51,11 @@ class Worker {
|
|
|
94
51
|
});
|
|
95
52
|
return;
|
|
96
53
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
if (skippedDeferral && delivery.isLastAttempt) {
|
|
106
|
-
this._logLost({
|
|
107
|
-
retryAt: validDate(error.retryAt)?.toISOString(),
|
|
108
|
-
reason: error.reason,
|
|
109
|
-
module: error.module,
|
|
110
|
-
...skippedDeferral,
|
|
111
|
-
error,
|
|
112
|
-
});
|
|
113
|
-
} else {
|
|
114
|
-
// The message goes back to SQS, so WARN (ADR-048 §4).
|
|
115
|
-
log.warn('Record failed, returned for retry', {
|
|
116
|
-
eventName: 'frigg.worker.record_failed',
|
|
117
|
-
error,
|
|
118
|
-
...skippedDeferral,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
54
|
+
// The message goes back to SQS, so WARN (ADR-048 §4).
|
|
55
|
+
log.warn('Record failed, returned for retry', {
|
|
56
|
+
eventName: 'frigg.worker.record_failed',
|
|
57
|
+
error,
|
|
58
|
+
});
|
|
121
59
|
batchItemFailures.push({ itemIdentifier: record.messageId });
|
|
122
60
|
}
|
|
123
61
|
});
|
|
@@ -137,251 +75,6 @@ class Worker {
|
|
|
137
75
|
// parameters
|
|
138
76
|
}
|
|
139
77
|
|
|
140
|
-
async defer(record, body, error, delivery) {
|
|
141
|
-
const retryAt = validDate(error.retryAt);
|
|
142
|
-
if (!retryAt) return { outcome: 'skipped', skipped: 'no_retry_at' };
|
|
143
|
-
const queueName = queueNameOf(record.eventSourceARN);
|
|
144
|
-
if (!queueName || queueName.endsWith('.fifo')) {
|
|
145
|
-
return { outcome: 'skipped', skipped: 'no_event_source' };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const now = Date.now();
|
|
149
|
-
const counters = nextDeferral(body, now, record.messageId);
|
|
150
|
-
const deferral = {
|
|
151
|
-
record,
|
|
152
|
-
queueName,
|
|
153
|
-
body,
|
|
154
|
-
deferredBody: withDeferral(body, counters),
|
|
155
|
-
error,
|
|
156
|
-
delivery,
|
|
157
|
-
retryAt,
|
|
158
|
-
waitMs: Math.max(0, retryAt.getTime() - now),
|
|
159
|
-
counters,
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const limits = readDeferralLimits();
|
|
163
|
-
if (isDeferralCapped({ ...counters, retryAt }, limits)) {
|
|
164
|
-
await this._recordWait(deferral, 'EXHAUSTED', 'none');
|
|
165
|
-
this._logUnacked(
|
|
166
|
-
deferral,
|
|
167
|
-
'record_deferral_capped',
|
|
168
|
-
'Rate-limit deferral capped',
|
|
169
|
-
{
|
|
170
|
-
maxDeferrals: limits.maxDeferrals,
|
|
171
|
-
maxDeferredMs: limits.maxDeferredMs,
|
|
172
|
-
deferredMs: deferredMs({ ...counters, retryAt }),
|
|
173
|
-
}
|
|
174
|
-
);
|
|
175
|
-
return { outcome: 'failed' };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (deferral.waitMs <= MAX_DELAY_SECONDS * 1000)
|
|
179
|
-
return this._deferWithDelay(deferral);
|
|
180
|
-
const scheduled = await this._deferWithSchedule(deferral);
|
|
181
|
-
if (scheduled?.outcome) return scheduled;
|
|
182
|
-
return this._deferWithVisibility(deferral, scheduled?.scheduleError);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async _deferWithDelay(deferral) {
|
|
186
|
-
const delaySeconds = Math.ceil(deferral.waitMs / 1000);
|
|
187
|
-
// Write the wait before the send: with a short delay the new message
|
|
188
|
-
// can run, and clear the wait, before a later write lands.
|
|
189
|
-
await this._recordWait(deferral, 'WAITING', 'delay');
|
|
190
|
-
try {
|
|
191
|
-
const queueUrl = await this._queueUrl(deferral.queueName);
|
|
192
|
-
await this.send(
|
|
193
|
-
{ ...deferral.deferredBody, QueueUrl: queueUrl },
|
|
194
|
-
delaySeconds
|
|
195
|
-
);
|
|
196
|
-
} catch (cause) {
|
|
197
|
-
await this._clearWait(deferral.body, deferral.counters.deferralId);
|
|
198
|
-
return { outcome: 'skipped', skipped: 'send_failed', cause };
|
|
199
|
-
}
|
|
200
|
-
return this._acknowledgeDeferral(deferral, 'delay', { delaySeconds });
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async _deferWithSchedule(deferral) {
|
|
204
|
-
const { record, retryAt, deferredBody } = deferral;
|
|
205
|
-
const scheduleName = `frigg-defer-${record.messageId}`;
|
|
206
|
-
try {
|
|
207
|
-
const scheduler = this.getSchedulerService();
|
|
208
|
-
if (!scheduler) return null;
|
|
209
|
-
await scheduler.scheduleOneTime({
|
|
210
|
-
scheduleName,
|
|
211
|
-
scheduleAt: retryAt,
|
|
212
|
-
queueResourceId: record.eventSourceARN,
|
|
213
|
-
payload: deferredBody,
|
|
214
|
-
});
|
|
215
|
-
} catch (cause) {
|
|
216
|
-
if (cause?.name !== 'ConflictException')
|
|
217
|
-
return { scheduleError: cause };
|
|
218
|
-
}
|
|
219
|
-
await this._recordWait(deferral, 'WAITING', 'schedule');
|
|
220
|
-
return this._acknowledgeDeferral(deferral, 'schedule', {
|
|
221
|
-
scheduleName,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async _deferWithVisibility(deferral, scheduleError) {
|
|
226
|
-
const { record, queueName, delivery, waitMs } = deferral;
|
|
227
|
-
const visibilityTimeout = Math.min(
|
|
228
|
-
Math.ceil(waitMs / 1000),
|
|
229
|
-
MAX_DEFERRED_VISIBILITY_SECONDS
|
|
230
|
-
);
|
|
231
|
-
try {
|
|
232
|
-
const queueUrl = await this._queueUrl(queueName);
|
|
233
|
-
await sqs.send(
|
|
234
|
-
new ChangeMessageVisibilityCommand({
|
|
235
|
-
QueueUrl: queueUrl,
|
|
236
|
-
ReceiptHandle: record.receiptHandle,
|
|
237
|
-
VisibilityTimeout: visibilityTimeout,
|
|
238
|
-
})
|
|
239
|
-
);
|
|
240
|
-
} catch (cause) {
|
|
241
|
-
return { outcome: 'skipped', skipped: 'visibility_failed', cause };
|
|
242
|
-
}
|
|
243
|
-
await this._recordWait(
|
|
244
|
-
deferral,
|
|
245
|
-
delivery.isLastAttempt ? 'EXHAUSTED' : 'WAITING',
|
|
246
|
-
'visibility'
|
|
247
|
-
);
|
|
248
|
-
this._logUnacked(
|
|
249
|
-
deferral,
|
|
250
|
-
'record_visibility_extended',
|
|
251
|
-
'Record visibility extended',
|
|
252
|
-
{
|
|
253
|
-
mechanism: 'visibility',
|
|
254
|
-
visibilityTimeout,
|
|
255
|
-
...(scheduleError && { scheduleError }),
|
|
256
|
-
}
|
|
257
|
-
);
|
|
258
|
-
return { outcome: 'failed' };
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
async _acknowledgeDeferral(deferral, mechanism, fields) {
|
|
262
|
-
log.warn('Record deferred', {
|
|
263
|
-
eventName: 'frigg.worker.record_deferred',
|
|
264
|
-
mechanism,
|
|
265
|
-
...fields,
|
|
266
|
-
...this._deferralLogFields(deferral),
|
|
267
|
-
error: deferral.error,
|
|
268
|
-
});
|
|
269
|
-
return { outcome: 'acked' };
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
getSchedulerService() {
|
|
273
|
-
if (this._schedulerService !== undefined) return this._schedulerService;
|
|
274
|
-
if (
|
|
275
|
-
!process.env.SCHEDULER_ROLE_ARN ||
|
|
276
|
-
process.env.SCHEDULER_PROVIDER === 'mock'
|
|
277
|
-
) {
|
|
278
|
-
this._schedulerService = null;
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
const {
|
|
282
|
-
createSchedulerService,
|
|
283
|
-
SCHEDULER_PROVIDERS,
|
|
284
|
-
} = require('../infrastructure/scheduler/scheduler-service-factory');
|
|
285
|
-
this._schedulerService = createSchedulerService({
|
|
286
|
-
provider: SCHEDULER_PROVIDERS.EVENTBRIDGE,
|
|
287
|
-
});
|
|
288
|
-
return this._schedulerService;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
recordRateLimitWait() {
|
|
292
|
-
return Promise.resolve();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
clearRateLimitWait() {
|
|
296
|
-
return Promise.resolve();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
_queueUrl(queueName) {
|
|
300
|
-
this._queueUrls ??= new Map();
|
|
301
|
-
if (!this._queueUrls.has(queueName)) {
|
|
302
|
-
const lookup = this.getQueueURL({ QueueName: queueName }).catch(
|
|
303
|
-
(error) => {
|
|
304
|
-
this._queueUrls.delete(queueName);
|
|
305
|
-
throw error;
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
this._queueUrls.set(queueName, lookup);
|
|
309
|
-
}
|
|
310
|
-
return this._queueUrls.get(queueName);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
async _recordWait({ body, error, counters, retryAt }, status, mechanism) {
|
|
314
|
-
await this._runStateHook('record', () =>
|
|
315
|
-
this.recordRateLimitWait(body, error, {
|
|
316
|
-
status,
|
|
317
|
-
mechanism,
|
|
318
|
-
deferrals: counters.deferrals,
|
|
319
|
-
deferralId: counters.deferralId,
|
|
320
|
-
retryAt,
|
|
321
|
-
})
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
async _clearDeferredState(record, body, delivery) {
|
|
326
|
-
const redelivered = delivery.receiveCount > 1;
|
|
327
|
-
const { deferrals, deferralId } = readDeferral(body);
|
|
328
|
-
if (deferrals === 0 && !redelivered) return;
|
|
329
|
-
await this._clearWait(body, deferralId ?? record.messageId);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
async _clearWait(body, deferralId) {
|
|
333
|
-
await this._runStateHook('clear', () =>
|
|
334
|
-
this.clearRateLimitWait(body, { deferralId })
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
async _runStateHook(operation, hook) {
|
|
339
|
-
try {
|
|
340
|
-
await hook();
|
|
341
|
-
} catch (error) {
|
|
342
|
-
log.warn('Rate-limit run state not written', {
|
|
343
|
-
eventName: 'frigg.worker.rate_limit_state_failed',
|
|
344
|
-
operation,
|
|
345
|
-
error,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
_deferralLogFields({ error, retryAt, waitMs, counters }) {
|
|
351
|
-
return {
|
|
352
|
-
waitMs,
|
|
353
|
-
retryAt: retryAt.toISOString(),
|
|
354
|
-
deferrals: counters.deferrals,
|
|
355
|
-
firstDeferredAt: counters.firstDeferredAt,
|
|
356
|
-
reason: error.reason,
|
|
357
|
-
module: error.module,
|
|
358
|
-
statusCode: error.statusCode,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
_logUnacked(deferral, eventName, message, fields) {
|
|
363
|
-
const logFields = {
|
|
364
|
-
...fields,
|
|
365
|
-
...this._deferralLogFields(deferral),
|
|
366
|
-
error: deferral.error,
|
|
367
|
-
};
|
|
368
|
-
if (deferral.delivery.isLastAttempt) {
|
|
369
|
-
this._logLost(logFields);
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
log.warn(message, {
|
|
373
|
-
eventName: `frigg.worker.${eventName}`,
|
|
374
|
-
...logFields,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
_logLost(fields) {
|
|
379
|
-
log.error(
|
|
380
|
-
'Rate-limited record lost: the message goes to the dead-letter queue next',
|
|
381
|
-
{ eventName: 'frigg.worker.record_lost_rate_limited', ...fields }
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
78
|
// returns the message id
|
|
386
79
|
async send(params, delay = 0) {
|
|
387
80
|
this._validateParams(params);
|
|
@@ -31,6 +31,7 @@ class RateLimitError extends FetchError {
|
|
|
31
31
|
super(fetchErrorArgs);
|
|
32
32
|
|
|
33
33
|
const timing = resolveTiming({ hint, waitMs, now });
|
|
34
|
+
this.statusCode ??= fetchErrorArgs.cause?.statusCode;
|
|
34
35
|
this.isRateLimited = true;
|
|
35
36
|
this.waitMs = timing.waitMs;
|
|
36
37
|
this.retryAt = timing.retryAt;
|
|
@@ -21,12 +21,6 @@ const {
|
|
|
21
21
|
getModulesDefinitionFromIntegrationClasses,
|
|
22
22
|
} = require('../integrations/utils/map-integration-dto');
|
|
23
23
|
const { processNotFound } = require('../integrations/use-cases/process-errors');
|
|
24
|
-
const {
|
|
25
|
-
RecordRateLimitWait,
|
|
26
|
-
} = require('../integrations/use-cases/record-rate-limit-wait');
|
|
27
|
-
const {
|
|
28
|
-
ClearRateLimitWait,
|
|
29
|
-
} = require('../integrations/use-cases/clear-rate-limit-wait');
|
|
30
24
|
|
|
31
25
|
const loadRouterFromObject = (IntegrationClass, routerObject) => {
|
|
32
26
|
const router = Router();
|
|
@@ -171,28 +165,6 @@ const createQueueWorker = (integrationClass) => {
|
|
|
171
165
|
const integrationName = integrationClass.Definition.name;
|
|
172
166
|
|
|
173
167
|
class QueueWorker extends Worker {
|
|
174
|
-
async recordRateLimitWait(body, error, state) {
|
|
175
|
-
const processId = body.data?.processId;
|
|
176
|
-
if (!processId) return;
|
|
177
|
-
const recordRateLimitWait = new RecordRateLimitWait({
|
|
178
|
-
processRepository: createProcessRepository(),
|
|
179
|
-
});
|
|
180
|
-
await recordRateLimitWait.execute(processId, {
|
|
181
|
-
...state,
|
|
182
|
-
reason: error.reason,
|
|
183
|
-
module: error.module,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async clearRateLimitWait(body, { deferralId } = {}) {
|
|
188
|
-
const processId = body?.data?.processId;
|
|
189
|
-
if (!processId) return;
|
|
190
|
-
const clearRateLimitWait = new ClearRateLimitWait({
|
|
191
|
-
processRepository: createProcessRepository(),
|
|
192
|
-
});
|
|
193
|
-
await clearRateLimitWait.execute(processId, { deferralId });
|
|
194
|
-
}
|
|
195
|
-
|
|
196
168
|
async _run(params, context, delivery) {
|
|
197
169
|
const logCtx = {
|
|
198
170
|
integration: integrationName,
|
|
@@ -313,8 +285,7 @@ const createQueueWorker = (integrationClass) => {
|
|
|
313
285
|
status >= 400 &&
|
|
314
286
|
status < 500 &&
|
|
315
287
|
status !== 408 &&
|
|
316
|
-
status !== 429
|
|
317
|
-
!error.isRateLimited
|
|
288
|
+
status !== 429
|
|
318
289
|
) {
|
|
319
290
|
error.isHaltError = true;
|
|
320
291
|
console.warn(
|
|
@@ -20,14 +20,12 @@ const {
|
|
|
20
20
|
} = require('@aws-sdk/client-scheduler');
|
|
21
21
|
|
|
22
22
|
const { SchedulerServiceInterface } = require('./scheduler-service-interface');
|
|
23
|
-
const { awsConfigOptions } = require('../../queues/queuer-util');
|
|
24
23
|
|
|
25
24
|
class EventBridgeSchedulerAdapter extends SchedulerServiceInterface {
|
|
26
25
|
constructor({ region } = {}) {
|
|
27
26
|
super();
|
|
28
27
|
this.client = new SchedulerClient({
|
|
29
28
|
region: region || process.env.AWS_REGION || 'us-east-1',
|
|
30
|
-
...awsConfigOptions(),
|
|
31
29
|
});
|
|
32
30
|
this.scheduleGroupName =
|
|
33
31
|
process.env.SCHEDULE_GROUP_NAME || 'frigg-integration-schedules';
|
|
@@ -6,8 +6,6 @@ const { CreateProcess } = require('./create-process');
|
|
|
6
6
|
const { UpdateProcessState } = require('./update-process-state');
|
|
7
7
|
const { UpdateProcessMetrics } = require('./update-process-metrics');
|
|
8
8
|
const { GetProcess } = require('./get-process');
|
|
9
|
-
const { RecordRateLimitWait } = require('./record-rate-limit-wait');
|
|
10
|
-
const { ClearRateLimitWait } = require('./clear-rate-limit-wait');
|
|
11
9
|
|
|
12
10
|
module.exports = {
|
|
13
11
|
GetIntegrationsForUser,
|
|
@@ -18,6 +16,4 @@ module.exports = {
|
|
|
18
16
|
UpdateProcessState,
|
|
19
17
|
UpdateProcessMetrics,
|
|
20
18
|
GetProcess,
|
|
21
|
-
|
|
22
|
-
ClearRateLimitWait,
|
|
23
|
-
};
|
|
19
|
+
};
|
|
@@ -398,13 +398,6 @@ class OAuth2Requester extends Requester {
|
|
|
398
398
|
);
|
|
399
399
|
transportError.statusCode = status;
|
|
400
400
|
transportError.isTokenRefreshTransportFailure = true;
|
|
401
|
-
if (error?.isRateLimited) {
|
|
402
|
-
transportError.isRateLimited = true;
|
|
403
|
-
transportError.retryAt = error.retryAt;
|
|
404
|
-
transportError.waitMs = error.waitMs;
|
|
405
|
-
transportError.reason = error.reason;
|
|
406
|
-
transportError.module = error.module;
|
|
407
|
-
}
|
|
408
401
|
return transportError;
|
|
409
402
|
}
|
|
410
403
|
|
|
@@ -110,9 +110,9 @@ function computeScopeKey(policy, requester) {
|
|
|
110
110
|
if (typeof scope === 'function') {
|
|
111
111
|
try {
|
|
112
112
|
const value = scope(requester);
|
|
113
|
-
return value ===
|
|
114
|
-
?
|
|
115
|
-
:
|
|
113
|
+
return typeof value === 'string' || Number.isFinite(value)
|
|
114
|
+
? `${label}:custom:${value}`
|
|
115
|
+
: undefined;
|
|
116
116
|
} catch {
|
|
117
117
|
return undefined;
|
|
118
118
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/core",
|
|
3
3
|
"prettier": "@friggframework/prettier-config",
|
|
4
|
-
"version": "2.0.0--canary.
|
|
4
|
+
"version": "2.0.0--canary.656.602fc50.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
|
|
7
7
|
"@aws-sdk/client-kms": "^3.588.0",
|
|
8
8
|
"@aws-sdk/client-lambda": "^3.714.0",
|
|
9
9
|
"@aws-sdk/client-s3": "^3.588.0",
|
|
10
|
-
"@aws-sdk/client-scheduler": "^3.588.0",
|
|
11
10
|
"@aws-sdk/client-sqs": "^3.588.0",
|
|
12
11
|
"@aws-sdk/client-ssm": "^3.588.0",
|
|
13
12
|
"@aws-sdk/s3-request-presigner": "^3.588.0",
|
|
@@ -48,13 +47,12 @@
|
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@friggframework/eslint-config": "2.0.0--canary.
|
|
52
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
53
|
-
"@friggframework/test": "2.0.0--canary.
|
|
50
|
+
"@friggframework/eslint-config": "2.0.0--canary.656.602fc50.0",
|
|
51
|
+
"@friggframework/prettier-config": "2.0.0--canary.656.602fc50.0",
|
|
52
|
+
"@friggframework/test": "2.0.0--canary.656.602fc50.0",
|
|
54
53
|
"@prisma/client": "^6.19.3",
|
|
55
54
|
"@types/lodash": "4.17.15",
|
|
56
55
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
57
|
-
"aws-sdk-client-mock": "^4.1.0",
|
|
58
56
|
"chai": "^4.3.6",
|
|
59
57
|
"eslint": "^8.22.0",
|
|
60
58
|
"eslint-plugin-import": "^2.29.1",
|
|
@@ -91,5 +89,5 @@
|
|
|
91
89
|
"publishConfig": {
|
|
92
90
|
"access": "public"
|
|
93
91
|
},
|
|
94
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "602fc501b2b433a6e220d651c369939ad0ec6245"
|
|
95
93
|
}
|
package/queues/queue-delivery.js
CHANGED
package/queues/queuer-util.js
CHANGED
package/types/core/index.d.ts
CHANGED
|
@@ -47,27 +47,8 @@ declare module "@friggframework/core" {
|
|
|
47
47
|
send(params: object & { QueueUrl: any }, delay?: number): Promise<string>;
|
|
48
48
|
|
|
49
49
|
sendAsyncSQSMessage(params: SendSQSMessageParams): Promise<string>;
|
|
50
|
-
|
|
51
|
-
recordRateLimitWait(
|
|
52
|
-
body: object,
|
|
53
|
-
error: Error,
|
|
54
|
-
state: RateLimitWaitState
|
|
55
|
-
): Promise<void>;
|
|
56
|
-
|
|
57
|
-
clearRateLimitWait(
|
|
58
|
-
body: object,
|
|
59
|
-
options?: { deferralId?: string }
|
|
60
|
-
): Promise<void>;
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
export type RateLimitWaitState = {
|
|
64
|
-
status: "WAITING" | "EXHAUSTED";
|
|
65
|
-
mechanism: "delay" | "schedule" | "visibility" | "none";
|
|
66
|
-
deferrals: number;
|
|
67
|
-
deferralId?: string;
|
|
68
|
-
retryAt: Date;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
52
|
interface IWorker {
|
|
72
53
|
getQueueURL(params: GetQueueURLParams): Promise<string | undefined>;
|
|
73
54
|
run(params: { Records: any }, context?: object): Promise<BatchItemFailuresResponse>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const CLEAR_RATE_LIMIT_TOLERANCE_MS = 5_000;
|
|
2
|
-
|
|
3
|
-
const isOwnWait = (current, deferralId) =>
|
|
4
|
-
Boolean(deferralId) && current.deferralId === deferralId;
|
|
5
|
-
|
|
6
|
-
const isOver = (current) =>
|
|
7
|
-
Date.parse(current.retryAt) - Date.now() <= CLEAR_RATE_LIMIT_TOLERANCE_MS;
|
|
8
|
-
|
|
9
|
-
class ClearRateLimitWait {
|
|
10
|
-
constructor({ processRepository }) {
|
|
11
|
-
if (!processRepository) {
|
|
12
|
-
throw new Error('processRepository is required');
|
|
13
|
-
}
|
|
14
|
-
this.processRepository = processRepository;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async execute(processId, { deferralId } = {}) {
|
|
18
|
-
const process = await this.processRepository.findById(processId);
|
|
19
|
-
const current = process?.context?.rateLimit;
|
|
20
|
-
if (current?.status !== 'WAITING') return;
|
|
21
|
-
if (!isOwnWait(current, deferralId) && !isOver(current)) return;
|
|
22
|
-
await this.processRepository.applyProcessUpdate(processId, {
|
|
23
|
-
set: { 'context.rateLimit': null },
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = { ClearRateLimitWait };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const keepsCurrentRateLimit = (current, next) => {
|
|
2
|
-
if (!current) return false;
|
|
3
|
-
if (next.status === 'EXHAUSTED') return false;
|
|
4
|
-
if (current.status === 'EXHAUSTED') return true;
|
|
5
|
-
return Date.parse(current.retryAt) > next.retryAt.getTime();
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
class RecordRateLimitWait {
|
|
9
|
-
constructor({ processRepository }) {
|
|
10
|
-
if (!processRepository) {
|
|
11
|
-
throw new Error('processRepository is required');
|
|
12
|
-
}
|
|
13
|
-
this.processRepository = processRepository;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async execute(processId, wait) {
|
|
17
|
-
const process = await this.processRepository.findById(processId);
|
|
18
|
-
if (keepsCurrentRateLimit(process?.context?.rateLimit, wait)) return;
|
|
19
|
-
await this.processRepository.applyProcessUpdate(processId, {
|
|
20
|
-
set: {
|
|
21
|
-
'context.rateLimit': {
|
|
22
|
-
status: wait.status,
|
|
23
|
-
mechanism: wait.mechanism,
|
|
24
|
-
retryAt: wait.retryAt.toISOString(),
|
|
25
|
-
reason: wait.reason,
|
|
26
|
-
module: wait.module,
|
|
27
|
-
deferrals: wait.deferrals,
|
|
28
|
-
deferralId: wait.deferralId,
|
|
29
|
-
updatedAt: new Date().toISOString(),
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = { RecordRateLimitWait };
|
package/queues/queue-deferral.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const { toPositiveInteger } = require('./queue-delivery');
|
|
2
|
-
|
|
3
|
-
const MAX_DEFERRALS = 30;
|
|
4
|
-
const MAX_DEFERRED_MS = 26 * 60 * 60 * 1000;
|
|
5
|
-
const MAX_DELAY_SECONDS = 900;
|
|
6
|
-
const MAX_VISIBILITY_TIMEOUT_SECONDS = 43_200;
|
|
7
|
-
const MAX_LAMBDA_RUN_SECONDS = 900;
|
|
8
|
-
const MAX_BATCHING_WINDOW_SECONDS = 300;
|
|
9
|
-
const MAX_DEFERRED_VISIBILITY_SECONDS =
|
|
10
|
-
MAX_VISIBILITY_TIMEOUT_SECONDS -
|
|
11
|
-
MAX_LAMBDA_RUN_SECONDS -
|
|
12
|
-
MAX_BATCHING_WINDOW_SECONDS;
|
|
13
|
-
const MAX_DEFERRALS_ENV = 'FRIGG_QUEUE_MAX_DEFERRALS';
|
|
14
|
-
const MAX_DEFERRED_MS_ENV = 'FRIGG_QUEUE_MAX_DEFERRED_MS';
|
|
15
|
-
|
|
16
|
-
const readDeferralLimits = (env = process.env) => ({
|
|
17
|
-
maxDeferrals: toPositiveInteger(env[MAX_DEFERRALS_ENV]) ?? MAX_DEFERRALS,
|
|
18
|
-
maxDeferredMs:
|
|
19
|
-
toPositiveInteger(env[MAX_DEFERRED_MS_ENV]) ?? MAX_DEFERRED_MS,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const readDeferral = (body) => {
|
|
23
|
-
const frigg = body?._frigg;
|
|
24
|
-
const deferrals =
|
|
25
|
-
Number.isInteger(frigg?.deferrals) && frigg.deferrals > 0
|
|
26
|
-
? frigg.deferrals
|
|
27
|
-
: 0;
|
|
28
|
-
const firstDeferredAt =
|
|
29
|
-
typeof frigg?.firstDeferredAt === 'string' &&
|
|
30
|
-
!Number.isNaN(Date.parse(frigg.firstDeferredAt))
|
|
31
|
-
? frigg.firstDeferredAt
|
|
32
|
-
: undefined;
|
|
33
|
-
const deferralId =
|
|
34
|
-
typeof frigg?.deferralId === 'string' && frigg.deferralId !== ''
|
|
35
|
-
? frigg.deferralId
|
|
36
|
-
: undefined;
|
|
37
|
-
return { deferrals, firstDeferredAt, deferralId };
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const nextDeferral = (body, now = Date.now(), messageId) => {
|
|
41
|
-
const current = readDeferral(body);
|
|
42
|
-
return {
|
|
43
|
-
deferrals: current.deferrals + 1,
|
|
44
|
-
firstDeferredAt: current.firstDeferredAt ?? new Date(now).toISOString(),
|
|
45
|
-
deferralId: current.deferralId ?? messageId,
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const withDeferral = (body, deferral) => ({
|
|
50
|
-
...body,
|
|
51
|
-
_frigg: { ...body._frigg, ...deferral },
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const deferredMs = ({ firstDeferredAt, retryAt }) =>
|
|
55
|
-
retryAt.getTime() - Date.parse(firstDeferredAt);
|
|
56
|
-
|
|
57
|
-
const isDeferralCapped = (deferral, { maxDeferrals, maxDeferredMs }) =>
|
|
58
|
-
deferral.deferrals > maxDeferrals || deferredMs(deferral) > maxDeferredMs;
|
|
59
|
-
|
|
60
|
-
module.exports = {
|
|
61
|
-
MAX_DEFERRALS,
|
|
62
|
-
MAX_DEFERRALS_ENV,
|
|
63
|
-
MAX_DEFERRED_MS,
|
|
64
|
-
MAX_DEFERRED_MS_ENV,
|
|
65
|
-
MAX_DEFERRED_VISIBILITY_SECONDS,
|
|
66
|
-
MAX_DELAY_SECONDS,
|
|
67
|
-
MAX_VISIBILITY_TIMEOUT_SECONDS,
|
|
68
|
-
deferredMs,
|
|
69
|
-
isDeferralCapped,
|
|
70
|
-
nextDeferral,
|
|
71
|
-
readDeferral,
|
|
72
|
-
readDeferralLimits,
|
|
73
|
-
withDeferral,
|
|
74
|
-
};
|