@friggframework/core 2.0.0--canary.657.18fb0ee.0 → 2.0.0--canary.657.798cee9.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/core/CLAUDE.md CHANGED
@@ -97,9 +97,12 @@ Each outcome writes one log record. `acked` writes WARN `record_deferred`.
97
97
  the last attempt they write one ERROR, `record_lost_rate_limited`, with the
98
98
  details, and no WARN.
99
99
 
100
- Subclasses override two no-op hooks to keep run state: `recordRateLimitWait(body,
101
- error, state)` runs after the message was put back, and `clearRateLimitWait(body,
102
- { deferralId })` runs after a deferred or redelivered message succeeded.
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.
103
106
  `state.deferralId` and `deferralId` name the message that was first put back
104
107
  (`_frigg.deferralId`, or the message's own id). A failing hook logs
105
108
  `frigg.worker.rate_limit_state_failed` and never changes the outcome. The queue
package/core/Worker.js CHANGED
@@ -184,6 +184,9 @@ class Worker {
184
184
 
185
185
  async _deferWithDelay(deferral) {
186
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');
187
190
  try {
188
191
  const queueUrl = await this._queueUrl(deferral.queueName);
189
192
  await this.send(
@@ -191,6 +194,7 @@ class Worker {
191
194
  delaySeconds
192
195
  );
193
196
  } catch (cause) {
197
+ await this._clearWait(deferral.body, deferral.counters.deferralId);
194
198
  return { outcome: 'skipped', skipped: 'send_failed', cause };
195
199
  }
196
200
  return this._acknowledgeDeferral(deferral, 'delay', { delaySeconds });
@@ -212,6 +216,7 @@ class Worker {
212
216
  if (cause?.name !== 'ConflictException')
213
217
  return { scheduleError: cause };
214
218
  }
219
+ await this._recordWait(deferral, 'WAITING', 'schedule');
215
220
  return this._acknowledgeDeferral(deferral, 'schedule', {
216
221
  scheduleName,
217
222
  });
@@ -254,7 +259,6 @@ class Worker {
254
259
  }
255
260
 
256
261
  async _acknowledgeDeferral(deferral, mechanism, fields) {
257
- await this._recordWait(deferral, 'WAITING', mechanism);
258
262
  log.warn('Record deferred', {
259
263
  eventName: 'frigg.worker.record_deferred',
260
264
  mechanism,
@@ -322,10 +326,12 @@ class Worker {
322
326
  const redelivered = delivery.receiveCount > 1;
323
327
  const { deferrals, deferralId } = readDeferral(body);
324
328
  if (deferrals === 0 && !redelivered) return;
329
+ await this._clearWait(body, deferralId ?? record.messageId);
330
+ }
331
+
332
+ async _clearWait(body, deferralId) {
325
333
  await this._runStateHook('clear', () =>
326
- this.clearRateLimitWait(body, {
327
- deferralId: deferralId ?? record.messageId,
328
- })
334
+ this.clearRateLimitWait(body, { deferralId })
329
335
  );
330
336
  }
331
337
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.657.18fb0ee.0",
4
+ "version": "2.0.0--canary.657.798cee9.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -48,9 +48,9 @@
48
48
  }
49
49
  },
50
50
  "devDependencies": {
51
- "@friggframework/eslint-config": "2.0.0--canary.657.18fb0ee.0",
52
- "@friggframework/prettier-config": "2.0.0--canary.657.18fb0ee.0",
53
- "@friggframework/test": "2.0.0--canary.657.18fb0ee.0",
51
+ "@friggframework/eslint-config": "2.0.0--canary.657.798cee9.0",
52
+ "@friggframework/prettier-config": "2.0.0--canary.657.798cee9.0",
53
+ "@friggframework/test": "2.0.0--canary.657.798cee9.0",
54
54
  "@prisma/client": "^6.19.3",
55
55
  "@types/lodash": "4.17.15",
56
56
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -91,5 +91,5 @@
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "18fb0eec33ecfe46362d17ff8660d06a929ae9ae"
94
+ "gitHead": "798cee9c975be131b5446e7d35fbfcceb5329a04"
95
95
  }