@friggframework/devtools 2.0.0--canary.743.c55fe7b.0 → 2.0.0--canary.743.81eabd1.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,10 @@ 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
|
+
queueWorkerMaximumConcurrency,
|
|
39
|
+
} = require('./queue-worker-concurrency');
|
|
36
40
|
const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
|
|
37
41
|
const {
|
|
38
42
|
INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
|
|
@@ -436,12 +440,18 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
436
440
|
|
|
437
441
|
// Create Queue Worker function
|
|
438
442
|
const queueWorkerName = `${integrationName}QueueWorker`;
|
|
443
|
+
const queueWorkerReservedConcurrency = 20;
|
|
444
|
+
// ADR-049 section 6, 2a: the modules' maxConcurrency caps the worker.
|
|
445
|
+
const maximumConcurrency = queueWorkerMaximumConcurrency(
|
|
446
|
+
integration,
|
|
447
|
+
queueWorkerReservedConcurrency
|
|
448
|
+
);
|
|
439
449
|
result.functions[queueWorkerName] = {
|
|
440
450
|
handler: `node_modules/@friggframework/core/handlers/workers/integration-defined-workers.handlers.${integrationName}.queueWorker`,
|
|
441
451
|
skipEsbuild: true, // Nested exports in node_modules - skip esbuild bundling
|
|
442
452
|
package: functionPackageConfig,
|
|
443
453
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }), // Queue workers need Prisma for database operations
|
|
444
|
-
reservedConcurrency:
|
|
454
|
+
reservedConcurrency: queueWorkerReservedConcurrency,
|
|
445
455
|
events: [
|
|
446
456
|
{
|
|
447
457
|
sqs: {
|
|
@@ -453,12 +463,20 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
453
463
|
},
|
|
454
464
|
batchSize: 1,
|
|
455
465
|
functionResponseType: 'ReportBatchItemFailures',
|
|
466
|
+
...(maximumConcurrency !== undefined && {
|
|
467
|
+
maximumConcurrency,
|
|
468
|
+
}),
|
|
456
469
|
},
|
|
457
470
|
},
|
|
458
471
|
],
|
|
459
472
|
timeout: 900, // 15 minutes max for queue workers (Lambda maximum)
|
|
460
473
|
};
|
|
461
474
|
console.log(` ✓ Queue worker function defined`);
|
|
475
|
+
if (maximumConcurrency !== undefined) {
|
|
476
|
+
console.log(
|
|
477
|
+
` ✓ Queue worker maximumConcurrency ${maximumConcurrency} (module maxConcurrency ${declaredMaxConcurrency(integration)})`
|
|
478
|
+
);
|
|
479
|
+
}
|
|
462
480
|
}
|
|
463
481
|
|
|
464
482
|
/**
|
|
@@ -393,6 +393,62 @@ 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
|
+
|
|
396
452
|
it('should add queue URL to environment variables', async () => {
|
|
397
453
|
const appDefinition = {
|
|
398
454
|
integrations: [
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
* The value is the smallest `maxConcurrency` of the integration's modules.
|
|
8
|
+
* It becomes the SQS event source's `maximumConcurrency`, which AWS bounds to
|
|
9
|
+
* 2..1000, and never more than the worker's reserved concurrency. An SQS
|
|
10
|
+
* event source that hits `maximumConcurrency` leaves the messages in the
|
|
11
|
+
* queue: unlike a lower reserved concurrency, it does not throttle them and
|
|
12
|
+
* does not spend their receives.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const SQS_MIN_MAXIMUM_CONCURRENCY = 2;
|
|
16
|
+
|
|
17
|
+
function moduleApiClasses(integration) {
|
|
18
|
+
const modules = integration?.Definition?.modules ?? {};
|
|
19
|
+
return Object.values(modules)
|
|
20
|
+
.map((entry) => (entry?.definition ?? entry)?.API)
|
|
21
|
+
.filter((API) => typeof API === 'function');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The smallest declared `maxConcurrency`, or undefined. */
|
|
25
|
+
function declaredMaxConcurrency(integration) {
|
|
26
|
+
let smallest;
|
|
27
|
+
for (const API of moduleApiClasses(integration)) {
|
|
28
|
+
let value;
|
|
29
|
+
try {
|
|
30
|
+
value = API.rateLimit?.maxConcurrency;
|
|
31
|
+
} catch {
|
|
32
|
+
value = undefined;
|
|
33
|
+
}
|
|
34
|
+
if (Number.isInteger(value) && value > 0) {
|
|
35
|
+
smallest =
|
|
36
|
+
smallest === undefined ? value : Math.min(smallest, value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return smallest;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @returns {number|undefined} the SQS `maximumConcurrency` for the queue
|
|
44
|
+
* worker, or undefined when no module declares `maxConcurrency` or the
|
|
45
|
+
* value is not below the reserved concurrency.
|
|
46
|
+
*/
|
|
47
|
+
function queueWorkerMaximumConcurrency(integration, reservedConcurrency) {
|
|
48
|
+
const declared = declaredMaxConcurrency(integration);
|
|
49
|
+
if (declared === undefined) return undefined;
|
|
50
|
+
const value = Math.max(declared, SQS_MIN_MAXIMUM_CONCURRENCY);
|
|
51
|
+
return value < reservedConcurrency ? value : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
SQS_MIN_MAXIMUM_CONCURRENCY,
|
|
56
|
+
declaredMaxConcurrency,
|
|
57
|
+
queueWorkerMaximumConcurrency,
|
|
58
|
+
};
|
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.
|
|
4
|
+
"version": "2.0.0--canary.743.81eabd1.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.
|
|
32
|
-
"@friggframework/schemas": "2.0.0--canary.743.
|
|
33
|
-
"@friggframework/test": "2.0.0--canary.743.
|
|
31
|
+
"@friggframework/core": "2.0.0--canary.743.81eabd1.0",
|
|
32
|
+
"@friggframework/schemas": "2.0.0--canary.743.81eabd1.0",
|
|
33
|
+
"@friggframework/test": "2.0.0--canary.743.81eabd1.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.
|
|
62
|
-
"@friggframework/prettier-config": "2.0.0--canary.743.
|
|
61
|
+
"@friggframework/eslint-config": "2.0.0--canary.743.81eabd1.0",
|
|
62
|
+
"@friggframework/prettier-config": "2.0.0--canary.743.81eabd1.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": "
|
|
94
|
+
"gitHead": "81eabd10e0cb7ab8384f240d96c98c88a0de4410"
|
|
95
95
|
}
|