@friggframework/devtools 2.0.0--canary.743.57dc4bf.0 → 2.0.0--canary.743.265a5cd.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.
@@ -33,6 +33,11 @@ const {
33
33
  nestedNodeModulesExcludes,
34
34
  } = require('../shared/utilities/nested-node-modules');
35
35
  const { queueArnFromUrl } = require('../shared/utilities/sqs-queue-arn');
36
+ const {
37
+ declaredMaxConcurrency,
38
+ queueWorkerConcurrencySource,
39
+ queueWorkerMaximumConcurrency,
40
+ } = require('./queue-worker-concurrency');
36
41
  const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
37
42
  const {
38
43
  INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
@@ -436,12 +441,19 @@ class IntegrationBuilder extends InfrastructureBuilder {
436
441
 
437
442
  // Create Queue Worker function
438
443
  const queueWorkerName = `${integrationName}QueueWorker`;
444
+ const queueWorkerReservedConcurrency = 20;
445
+ // ADR-049 section 6, 2a: the integration's queueWorker setting, else
446
+ // the modules' maxConcurrency, caps the whole queue worker.
447
+ const maximumConcurrency = queueWorkerMaximumConcurrency(
448
+ integration,
449
+ queueWorkerReservedConcurrency
450
+ );
439
451
  result.functions[queueWorkerName] = {
440
452
  handler: `node_modules/@friggframework/core/handlers/workers/integration-defined-workers.handlers.${integrationName}.queueWorker`,
441
453
  skipEsbuild: true, // Nested exports in node_modules - skip esbuild bundling
442
454
  package: functionPackageConfig,
443
455
  ...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }), // Queue workers need Prisma for database operations
444
- reservedConcurrency: 20,
456
+ reservedConcurrency: queueWorkerReservedConcurrency,
445
457
  events: [
446
458
  {
447
459
  sqs: {
@@ -453,12 +465,24 @@ class IntegrationBuilder extends InfrastructureBuilder {
453
465
  },
454
466
  batchSize: 1,
455
467
  functionResponseType: 'ReportBatchItemFailures',
468
+ ...(maximumConcurrency !== undefined && {
469
+ maximumConcurrency,
470
+ }),
456
471
  },
457
472
  },
458
473
  ],
459
474
  timeout: 900, // 15 minutes max for queue workers (Lambda maximum)
460
475
  };
461
476
  console.log(` ✓ Queue worker function defined`);
477
+ if (maximumConcurrency !== undefined) {
478
+ console.log(
479
+ ` ✓ Queue worker maximumConcurrency ${maximumConcurrency} for the whole queue (${
480
+ queueWorkerConcurrencySource(integration).source === 'integration'
481
+ ? 'Definition.queueWorker.maximumConcurrency'
482
+ : `smallest module maxConcurrency ${declaredMaxConcurrency(integration)}; set Definition.queueWorker.maximumConcurrency to change or false to turn off`
483
+ })`
484
+ );
485
+ }
462
486
  }
463
487
 
464
488
  /**
@@ -393,6 +393,86 @@ describe('IntegrationBuilder', () => {
393
393
  expect(result.functions.testQueueWorker.reservedConcurrency).toBe(20);
394
394
  });
395
395
 
396
+ describe('maximumConcurrency from the modules (ADR-049 section 6, 2a)', () => {
397
+ const withModules = (...limits) => ({
398
+ integrations: [
399
+ {
400
+ Definition: {
401
+ name: 'test',
402
+ modules: Object.fromEntries(
403
+ limits.map((maxConcurrency, i) => [
404
+ `m${i}`,
405
+ {
406
+ definition: {
407
+ API: class {
408
+ static rateLimit =
409
+ maxConcurrency === undefined
410
+ ? undefined
411
+ : { maxConcurrency };
412
+ },
413
+ },
414
+ },
415
+ ])
416
+ ),
417
+ },
418
+ },
419
+ ],
420
+ });
421
+ const sqsOf = (result) =>
422
+ result.functions.testQueueWorker.events[0].sqs;
423
+
424
+ it('sets the smallest maxConcurrency of the modules', async () => {
425
+ const result = await integrationBuilder.build(
426
+ withModules(10, 5, undefined),
427
+ {}
428
+ );
429
+ expect(sqsOf(result).maximumConcurrency).toBe(5);
430
+ expect(result.functions.testQueueWorker.reservedConcurrency).toBe(20);
431
+ });
432
+
433
+ it('raises a value under 2 to the SQS minimum of 2', async () => {
434
+ const result = await integrationBuilder.build(withModules(1), {});
435
+ expect(sqsOf(result).maximumConcurrency).toBe(2);
436
+ });
437
+
438
+ it('sets nothing when no module declares maxConcurrency', async () => {
439
+ const result = await integrationBuilder.build(
440
+ withModules(undefined),
441
+ {}
442
+ );
443
+ expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
444
+ });
445
+
446
+ it('sets nothing when the value is not below the reserved concurrency', async () => {
447
+ const result = await integrationBuilder.build(withModules(50), {});
448
+ expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
449
+ });
450
+
451
+ const withSetting = (setting, ...limits) => {
452
+ const app = withModules(...limits);
453
+ app.integrations[0].Definition.queueWorker = {
454
+ maximumConcurrency: setting,
455
+ };
456
+ return app;
457
+ };
458
+
459
+ it('uses Definition.queueWorker.maximumConcurrency over the modules', async () => {
460
+ const result = await integrationBuilder.build(
461
+ withSetting(8, 3),
462
+ {}
463
+ );
464
+ expect(sqsOf(result).maximumConcurrency).toBe(8);
465
+ });
466
+
467
+ it('sets nothing when Definition.queueWorker.maximumConcurrency is false', async () => {
468
+ const result = await integrationBuilder.build(
469
+ withSetting(false, 3),
470
+ {}
471
+ );
472
+ expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
473
+ });
474
+ });
475
+
396
476
  it('should add queue URL to environment variables', async () => {
397
477
  const appDefinition = {
398
478
  integrations: [
@@ -0,0 +1,79 @@
1
+ /**
2
+ * ADR-049 section 6, pacing 2a: the queue worker's maximum concurrency comes
3
+ * from the `maxConcurrency` that the integration's API modules declare in
4
+ * `static rateLimit`. The module only describes the provider; devtools
5
+ * decides the deployment.
6
+ *
7
+ * `maximumConcurrency` limits the whole queue of the integration, for every
8
+ * tenant, while `maxConcurrency` describes one key of the provider. So the
9
+ * integration decides it: `Definition.queueWorker.maximumConcurrency` sets
10
+ * it (an integer), or turns it off (`false`). When the integration sets
11
+ * nothing, the value is the smallest `maxConcurrency` of its modules.
12
+ * It becomes the SQS event source's `maximumConcurrency`, which AWS bounds to
13
+ * 2..1000, and never more than the worker's reserved concurrency. An SQS
14
+ * event source that hits `maximumConcurrency` leaves the messages in the
15
+ * queue: unlike a lower reserved concurrency, it does not throttle them and
16
+ * does not spend their receives.
17
+ */
18
+
19
+ const SQS_MIN_MAXIMUM_CONCURRENCY = 2;
20
+
21
+ function moduleApiClasses(integration) {
22
+ const modules = integration?.Definition?.modules ?? {};
23
+ return Object.values(modules)
24
+ .map((entry) => (entry?.definition ?? entry)?.API)
25
+ .filter((API) => typeof API === 'function');
26
+ }
27
+
28
+ /** The smallest declared `maxConcurrency`, or undefined. */
29
+ function declaredMaxConcurrency(integration) {
30
+ let smallest;
31
+ for (const API of moduleApiClasses(integration)) {
32
+ let value;
33
+ try {
34
+ value = API.rateLimit?.maxConcurrency;
35
+ } catch {
36
+ value = undefined;
37
+ }
38
+ if (Number.isInteger(value) && value > 0) {
39
+ smallest =
40
+ smallest === undefined ? value : Math.min(smallest, value);
41
+ }
42
+ }
43
+ return smallest;
44
+ }
45
+
46
+ /**
47
+ * Where the value comes from: the integration's own setting, or its modules.
48
+ * @returns {{ value: number|undefined, source: 'integration'|'modules'|'off'|'none' }}
49
+ */
50
+ function queueWorkerConcurrencySource(integration) {
51
+ const setting = integration?.Definition?.queueWorker?.maximumConcurrency;
52
+ if (setting === false) return { value: undefined, source: 'off' };
53
+ if (Number.isInteger(setting) && setting > 0) {
54
+ return { value: setting, source: 'integration' };
55
+ }
56
+ const declared = declaredMaxConcurrency(integration);
57
+ return declared === undefined
58
+ ? { value: undefined, source: 'none' }
59
+ : { value: declared, source: 'modules' };
60
+ }
61
+
62
+ /**
63
+ * @returns {number|undefined} the SQS `maximumConcurrency` for the queue
64
+ * worker, or undefined when it is off, nothing declares a value, or the
65
+ * value is not below the reserved concurrency.
66
+ */
67
+ function queueWorkerMaximumConcurrency(integration, reservedConcurrency) {
68
+ const declared = queueWorkerConcurrencySource(integration).value;
69
+ if (declared === undefined) return undefined;
70
+ const value = Math.max(declared, SQS_MIN_MAXIMUM_CONCURRENCY);
71
+ return value < reservedConcurrency ? value : undefined;
72
+ }
73
+
74
+ module.exports = {
75
+ SQS_MIN_MAXIMUM_CONCURRENCY,
76
+ declaredMaxConcurrency,
77
+ queueWorkerConcurrencySource,
78
+ queueWorkerMaximumConcurrency,
79
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/devtools",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.743.57dc4bf.0",
4
+ "version": "2.0.0--canary.743.265a5cd.0",
5
5
  "bin": {
6
6
  "frigg": "./frigg-cli/index.js"
7
7
  },
@@ -28,9 +28,9 @@
28
28
  "@babel/eslint-parser": "^7.18.9",
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
- "@friggframework/core": "2.0.0--canary.743.57dc4bf.0",
32
- "@friggframework/schemas": "2.0.0--canary.743.57dc4bf.0",
33
- "@friggframework/test": "2.0.0--canary.743.57dc4bf.0",
31
+ "@friggframework/core": "2.0.0--canary.743.265a5cd.0",
32
+ "@friggframework/schemas": "2.0.0--canary.743.265a5cd.0",
33
+ "@friggframework/test": "2.0.0--canary.743.265a5cd.0",
34
34
  "@hapi/boom": "^10.0.1",
35
35
  "@inquirer/prompts": "^5.3.8",
36
36
  "axios": "^1.18.0",
@@ -58,8 +58,8 @@
58
58
  "validate-npm-package-name": "^5.0.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@friggframework/eslint-config": "2.0.0--canary.743.57dc4bf.0",
62
- "@friggframework/prettier-config": "2.0.0--canary.743.57dc4bf.0",
61
+ "@friggframework/eslint-config": "2.0.0--canary.743.265a5cd.0",
62
+ "@friggframework/prettier-config": "2.0.0--canary.743.265a5cd.0",
63
63
  "aws-sdk-client-mock": "^4.1.0",
64
64
  "aws-sdk-client-mock-jest": "^4.1.0",
65
65
  "jest": "^30.1.3",
@@ -91,5 +91,5 @@
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "57dc4bfa7d4bd3dbf00a286355c7e4c041acd0fe"
94
+ "gitHead": "265a5cd5f39515f47164aec0b99fed86048b59d9"
95
95
  }