@friggframework/devtools 2.0.0--canary.743.a254104.0 → 2.0.0--canary.744.9a69fb7.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,11 +33,6 @@ 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');
|
|
41
36
|
const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
|
|
42
37
|
const {
|
|
43
38
|
INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
|
|
@@ -441,19 +436,12 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
441
436
|
|
|
442
437
|
// Create Queue Worker function
|
|
443
438
|
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
|
-
);
|
|
451
439
|
result.functions[queueWorkerName] = {
|
|
452
440
|
handler: `node_modules/@friggframework/core/handlers/workers/integration-defined-workers.handlers.${integrationName}.queueWorker`,
|
|
453
441
|
skipEsbuild: true, // Nested exports in node_modules - skip esbuild bundling
|
|
454
442
|
package: functionPackageConfig,
|
|
455
443
|
...(usePrismaLayer && { layers: [{ Ref: 'PrismaLambdaLayer' }] }), // Queue workers need Prisma for database operations
|
|
456
|
-
reservedConcurrency:
|
|
444
|
+
reservedConcurrency: 20,
|
|
457
445
|
events: [
|
|
458
446
|
{
|
|
459
447
|
sqs: {
|
|
@@ -465,33 +453,12 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
465
453
|
},
|
|
466
454
|
batchSize: 1,
|
|
467
455
|
functionResponseType: 'ReportBatchItemFailures',
|
|
468
|
-
...(maximumConcurrency !== undefined && {
|
|
469
|
-
maximumConcurrency,
|
|
470
|
-
}),
|
|
471
456
|
},
|
|
472
457
|
},
|
|
473
458
|
],
|
|
474
459
|
timeout: 900, // 15 minutes max for queue workers (Lambda maximum)
|
|
475
460
|
};
|
|
476
461
|
console.log(` ✓ Queue worker function defined`);
|
|
477
|
-
const concurrencySource = queueWorkerConcurrencySource(integration);
|
|
478
|
-
if (
|
|
479
|
-
maximumConcurrency === undefined &&
|
|
480
|
-
concurrencySource.value !== undefined
|
|
481
|
-
) {
|
|
482
|
-
console.log(
|
|
483
|
-
` ⚠ Queue worker maximumConcurrency ${concurrencySource.value} not set: it is not below the reserved concurrency of ${queueWorkerReservedConcurrency}`
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
if (maximumConcurrency !== undefined) {
|
|
487
|
-
console.log(
|
|
488
|
-
` ✓ Queue worker maximumConcurrency ${maximumConcurrency} for the whole queue (${
|
|
489
|
-
concurrencySource.source === 'integration'
|
|
490
|
-
? 'Definition.queueWorker.maximumConcurrency'
|
|
491
|
-
: `smallest module maxConcurrency ${declaredMaxConcurrency(integration)}; set Definition.queueWorker.maximumConcurrency to change or false to turn off`
|
|
492
|
-
})`
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
462
|
}
|
|
496
463
|
|
|
497
464
|
/**
|
|
@@ -393,92 +393,6 @@ 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('refuses a Definition.queueWorker.maximumConcurrency that is not an integer or false', async () => {
|
|
468
|
-
await expect(
|
|
469
|
-
integrationBuilder.build(withSetting('8', 3), {})
|
|
470
|
-
).rejects.toThrow('must be an integer from 2 to 1000, or false');
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it('sets nothing when Definition.queueWorker.maximumConcurrency is false', async () => {
|
|
474
|
-
const result = await integrationBuilder.build(
|
|
475
|
-
withSetting(false, 3),
|
|
476
|
-
{}
|
|
477
|
-
);
|
|
478
|
-
expect(sqsOf(result)).not.toHaveProperty('maximumConcurrency');
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
396
|
it('should add queue URL to environment variables', async () => {
|
|
483
397
|
const appDefinition = {
|
|
484
398
|
integrations: [
|
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.
|
|
4
|
+
"version": "2.0.0--canary.744.9a69fb7.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.
|
|
32
|
-
"@friggframework/schemas": "2.0.0--canary.
|
|
33
|
-
"@friggframework/test": "2.0.0--canary.
|
|
31
|
+
"@friggframework/core": "2.0.0--canary.744.9a69fb7.0",
|
|
32
|
+
"@friggframework/schemas": "2.0.0--canary.744.9a69fb7.0",
|
|
33
|
+
"@friggframework/test": "2.0.0--canary.744.9a69fb7.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.
|
|
62
|
-
"@friggframework/prettier-config": "2.0.0--canary.
|
|
61
|
+
"@friggframework/eslint-config": "2.0.0--canary.744.9a69fb7.0",
|
|
62
|
+
"@friggframework/prettier-config": "2.0.0--canary.744.9a69fb7.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": "9a69fb7c1880d0a1d7575e2e18a9fcf0fc76f37c"
|
|
95
95
|
}
|
|
@@ -1,85 +0,0 @@
|
|
|
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
|
-
* Throws for a setting that is neither a positive integer nor `false`.
|
|
49
|
-
* @returns {{ value: number|undefined, source: 'integration'|'modules'|'off'|'none' }}
|
|
50
|
-
*/
|
|
51
|
-
function queueWorkerConcurrencySource(integration) {
|
|
52
|
-
const setting = integration?.Definition?.queueWorker?.maximumConcurrency;
|
|
53
|
-
if (setting === false) return { value: undefined, source: 'off' };
|
|
54
|
-
if (Number.isInteger(setting) && setting > 0) {
|
|
55
|
-
return { value: setting, source: 'integration' };
|
|
56
|
-
}
|
|
57
|
-
if (setting !== undefined) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Definition.queueWorker.maximumConcurrency of integration "${integration?.Definition?.name}" must be an integer from 2 to 1000, or false`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
const declared = declaredMaxConcurrency(integration);
|
|
63
|
-
return declared === undefined
|
|
64
|
-
? { value: undefined, source: 'none' }
|
|
65
|
-
: { value: declared, source: 'modules' };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @returns {number|undefined} the SQS `maximumConcurrency` for the queue
|
|
70
|
-
* worker, or undefined when it is off, nothing declares a value, or the
|
|
71
|
-
* value is not below the reserved concurrency.
|
|
72
|
-
*/
|
|
73
|
-
function queueWorkerMaximumConcurrency(integration, reservedConcurrency) {
|
|
74
|
-
const declared = queueWorkerConcurrencySource(integration).value;
|
|
75
|
-
if (declared === undefined) return undefined;
|
|
76
|
-
const value = Math.max(declared, SQS_MIN_MAXIMUM_CONCURRENCY);
|
|
77
|
-
return value < reservedConcurrency ? value : undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = {
|
|
81
|
-
SQS_MIN_MAXIMUM_CONCURRENCY,
|
|
82
|
-
declaredMaxConcurrency,
|
|
83
|
-
queueWorkerConcurrencySource,
|
|
84
|
-
queueWorkerMaximumConcurrency,
|
|
85
|
-
};
|