@causa/runtime-google 0.35.0 → 0.35.1
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EVENT_PUBLISHER_INJECTION_NAME, Logger } from '@causa/runtime/nestjs';
|
|
2
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { PubSubPublisher } from '../../pubsub/index.js';
|
|
3
4
|
import { SpannerEntityManager } from '../../spanner/index.js';
|
|
4
5
|
import { SpannerOutboxEvent } from './event.js';
|
|
5
6
|
import { SpannerOutboxTransactionRunner } from './runner.js';
|
|
@@ -7,11 +8,12 @@ import { SpannerOutboxSender, } from './sender.js';
|
|
|
7
8
|
/**
|
|
8
9
|
* Combines options passed to the module with the configuration (from the environment).
|
|
9
10
|
*
|
|
10
|
-
* @param
|
|
11
|
+
* @param defaultOptions Options inferred by the module itself.
|
|
12
|
+
* @param customOptions Options passed to the module by the caller.
|
|
11
13
|
* @param config The {@link ConfigService} to use.
|
|
12
14
|
* @returns The parsed {@link SpannerOutboxSenderOptions}.
|
|
13
15
|
*/
|
|
14
|
-
function parseSenderOptions(
|
|
16
|
+
function parseSenderOptions(defaultOptions, customOptions, config) {
|
|
15
17
|
function validateIntOrUndefined(name) {
|
|
16
18
|
const strValue = config.get(name);
|
|
17
19
|
if (strValue === undefined) {
|
|
@@ -34,7 +36,7 @@ function parseSenderOptions(options, config) {
|
|
|
34
36
|
const sharding = shardingColumn && shardingCount
|
|
35
37
|
? { column: shardingColumn, count: shardingCount }
|
|
36
38
|
: undefined;
|
|
37
|
-
const
|
|
39
|
+
const envOptionsWithUndefined = {
|
|
38
40
|
batchSize,
|
|
39
41
|
pollingInterval,
|
|
40
42
|
idColumn,
|
|
@@ -43,8 +45,15 @@ function parseSenderOptions(options, config) {
|
|
|
43
45
|
sharding,
|
|
44
46
|
leaseDuration,
|
|
45
47
|
};
|
|
46
|
-
|
|
48
|
+
const envOptions = Object.fromEntries(Object.entries(envOptionsWithUndefined).filter(([, v]) => v !== undefined));
|
|
49
|
+
return { ...defaultOptions, ...envOptions, ...customOptions };
|
|
47
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The default lease duration, in milliseconds, when the publisher is Pub/Sub.
|
|
53
|
+
* Pub/Sub has a default retry/timeout of 60 seconds. This ensures the lease is long enough and the event doesn't get
|
|
54
|
+
* picked up by another instance.
|
|
55
|
+
*/
|
|
56
|
+
const DEFAULT_PUBSUB_LEASE_DURATION = 70000;
|
|
48
57
|
/**
|
|
49
58
|
* The module providing the {@link SpannerOutboxTransactionRunner}.
|
|
50
59
|
* This assumes the `SpannerModule` and an {@link EventPublisher} are available (as well as the `LoggerModule`).
|
|
@@ -69,7 +78,10 @@ export class SpannerOutboxTransactionModule {
|
|
|
69
78
|
{
|
|
70
79
|
provide: SpannerOutboxSender,
|
|
71
80
|
useFactory: (entityManager, publisher, logger, config) => {
|
|
72
|
-
const
|
|
81
|
+
const defaultOptions = publisher instanceof PubSubPublisher
|
|
82
|
+
? { leaseDuration: DEFAULT_PUBSUB_LEASE_DURATION }
|
|
83
|
+
: {};
|
|
84
|
+
const options = parseSenderOptions(defaultOptions, senderOptions, config);
|
|
73
85
|
return new SpannerOutboxSender(entityManager, outboxEventType, publisher, logger, options);
|
|
74
86
|
},
|
|
75
87
|
inject: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@causa/runtime-google",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.1",
|
|
4
4
|
"description": "An extension to the Causa runtime SDK (`@causa/runtime`), providing Google-specific features.",
|
|
5
5
|
"repository": "github:causa-io/runtime-typescript-google",
|
|
6
6
|
"license": "ISC",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@types/supertest": "^6.0.2",
|
|
63
63
|
"@types/uuid": "^10.0.0",
|
|
64
64
|
"dotenv": "^16.4.5",
|
|
65
|
-
"eslint": "^9.
|
|
65
|
+
"eslint": "^9.16.0",
|
|
66
66
|
"eslint-config-prettier": "^9.1.0",
|
|
67
67
|
"eslint-plugin-prettier": "^5.2.1",
|
|
68
68
|
"jest": "^29.7.0",
|