@shushed/helpers 0.0.58 → 0.0.59
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/dist/index.d.ts +20 -3
- package/dist/index.js +173 -70
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -28763,22 +28763,37 @@ declare function validate<T>(payload: T, schema: JSONSchemaType<T>, options: {
|
|
|
28763
28763
|
declare const sanitizeToString: DeepRedact;
|
|
28764
28764
|
declare const sanitize: DeepRedact;
|
|
28765
28765
|
|
|
28766
|
+
interface ILogging {
|
|
28767
|
+
log(...args: any[]): void;
|
|
28768
|
+
error(...args: any[]): void;
|
|
28769
|
+
}
|
|
28766
28770
|
type Opts = {
|
|
28767
28771
|
workflowId: string;
|
|
28768
28772
|
triggerId: string;
|
|
28769
28773
|
url: string;
|
|
28770
28774
|
envName: string;
|
|
28775
|
+
logging?: ILogging;
|
|
28771
28776
|
} | {
|
|
28772
28777
|
workflowId: string;
|
|
28773
28778
|
triggerId: string;
|
|
28774
28779
|
url: string;
|
|
28775
|
-
|
|
28780
|
+
logging?: ILogging;
|
|
28781
|
+
} | Runtime;
|
|
28782
|
+
declare class Logging implements ILogging {
|
|
28783
|
+
private workflowId;
|
|
28784
|
+
private triggerId;
|
|
28785
|
+
private systemEnvName;
|
|
28786
|
+
constructor(workflowId: string, triggerId: string, systemEnvName: string);
|
|
28787
|
+
log(...args: any[]): void;
|
|
28788
|
+
error(...args: any[]): void;
|
|
28789
|
+
}
|
|
28776
28790
|
declare class Runtime {
|
|
28777
28791
|
readonly workflowId: string;
|
|
28778
28792
|
readonly triggerId: string;
|
|
28779
28793
|
readonly envName: string;
|
|
28780
28794
|
readonly systemEnvName: string;
|
|
28781
28795
|
readonly runtimeUrl: string;
|
|
28796
|
+
readonly logging: ILogging;
|
|
28782
28797
|
constructor(opts: Opts);
|
|
28783
28798
|
}
|
|
28784
28799
|
|
|
@@ -28879,7 +28894,6 @@ declare class PubSubHelper extends Runtime {
|
|
|
28879
28894
|
private getNameFromFullyQualifiedName;
|
|
28880
28895
|
private updateSubscription;
|
|
28881
28896
|
private ensureSubscribtionExists;
|
|
28882
|
-
private ensureDLQSubscriptionExists;
|
|
28883
28897
|
deleteSubscriptions(topicName: string): Promise<{
|
|
28884
28898
|
mainTopic: Topic | undefined;
|
|
28885
28899
|
mainDlqTopic: Topic | undefined;
|
|
@@ -29229,8 +29243,11 @@ type index_BigQueryHelper = BigQueryHelper;
|
|
|
29229
29243
|
declare const index_BigQueryHelper: typeof BigQueryHelper;
|
|
29230
29244
|
type index_EnvEngine = EnvEngine;
|
|
29231
29245
|
declare const index_EnvEngine: typeof EnvEngine;
|
|
29246
|
+
type index_ILogging = ILogging;
|
|
29232
29247
|
type index_JWKSHelper = JWKSHelper;
|
|
29233
29248
|
declare const index_JWKSHelper: typeof JWKSHelper;
|
|
29249
|
+
type index_Logging = Logging;
|
|
29250
|
+
declare const index_Logging: typeof Logging;
|
|
29234
29251
|
type index_Message = Message;
|
|
29235
29252
|
type index_NodeOptions = NodeOptions;
|
|
29236
29253
|
type index_PubSubHelper = PubSubHelper;
|
|
@@ -29253,7 +29270,7 @@ declare const index_shortHash: typeof shortHash;
|
|
|
29253
29270
|
declare const index_validate: typeof validate;
|
|
29254
29271
|
declare const index_validateGoogleAuth: typeof validateGoogleAuth;
|
|
29255
29272
|
declare namespace index {
|
|
29256
|
-
export { index_BigQueryHelper as BigQueryHelper, index_EnvEngine as EnvEngine, index_JWKSHelper as JWKSHelper, type index_Message as Message, type index_NodeOptions as NodeOptions, index_PubSubHelper as PubSubHelper, index_Runtime as Runtime, index_SchedulerHelper as SchedulerHelper, index_Secrets as Secrets, type index_TriggerOnCreateOptions as TriggerOnCreateOptions, type index_TriggerOnExecuteOptions as TriggerOnExecuteOptions, index_getEventTime as getEventTime, index_isCronMessage as isCronMessage, index_isPubSubRequest as isPubSubRequest, index_parseDateOrDefault as parseDateOrDefault, index_sanitize as sanitize, index_sanitizeToString as sanitizeToString, index_shortHash as shortHash, index_validate as validate, index_validateGoogleAuth as validateGoogleAuth };
|
|
29273
|
+
export { index_BigQueryHelper as BigQueryHelper, index_EnvEngine as EnvEngine, type index_ILogging as ILogging, index_JWKSHelper as JWKSHelper, index_Logging as Logging, type index_Message as Message, type index_NodeOptions as NodeOptions, index_PubSubHelper as PubSubHelper, index_Runtime as Runtime, index_SchedulerHelper as SchedulerHelper, index_Secrets as Secrets, type index_TriggerOnCreateOptions as TriggerOnCreateOptions, type index_TriggerOnExecuteOptions as TriggerOnExecuteOptions, index_getEventTime as getEventTime, index_isCronMessage as isCronMessage, index_isPubSubRequest as isPubSubRequest, index_parseDateOrDefault as parseDateOrDefault, index_sanitize as sanitize, index_sanitizeToString as sanitizeToString, index_shortHash as shortHash, index_validate as validate, index_validateGoogleAuth as validateGoogleAuth };
|
|
29257
29274
|
}
|
|
29258
29275
|
|
|
29259
29276
|
export { index as lib, index$9 as schema, index$1 as types };
|
package/dist/index.js
CHANGED
|
@@ -288,6 +288,7 @@ __export(src_public_exports, {
|
|
|
288
288
|
BigQueryHelper: () => bigquery_default,
|
|
289
289
|
EnvEngine: () => env_default,
|
|
290
290
|
JWKSHelper: () => jwks_default,
|
|
291
|
+
Logging: () => Logging,
|
|
291
292
|
PubSubHelper: () => pubsub_default,
|
|
292
293
|
Runtime: () => Runtime,
|
|
293
294
|
SchedulerHelper: () => scheduler_default,
|
|
@@ -363,25 +364,63 @@ var import_jose = require("jose");
|
|
|
363
364
|
|
|
364
365
|
// src-public/runtime.ts
|
|
365
366
|
var DEFAULT_BRANCH = "migratedprod";
|
|
366
|
-
var
|
|
367
|
+
var Logging = class {
|
|
368
|
+
constructor(workflowId, triggerId, systemEnvName) {
|
|
369
|
+
this.workflowId = workflowId;
|
|
370
|
+
this.triggerId = triggerId;
|
|
371
|
+
this.systemEnvName = systemEnvName;
|
|
372
|
+
}
|
|
373
|
+
log(...args) {
|
|
374
|
+
console.log({
|
|
375
|
+
payload: args,
|
|
376
|
+
workflowId: this.workflowId,
|
|
377
|
+
wId: this.workflowId,
|
|
378
|
+
triggerId: this.triggerId,
|
|
379
|
+
tId: this.triggerId,
|
|
380
|
+
env: this.systemEnvName
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
error(...args) {
|
|
384
|
+
console.error({
|
|
385
|
+
payload: args,
|
|
386
|
+
workflowId: this.workflowId,
|
|
387
|
+
wId: this.workflowId,
|
|
388
|
+
triggerId: this.triggerId,
|
|
389
|
+
tId: this.triggerId,
|
|
390
|
+
env: this.systemEnvName
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
var Runtime = class _Runtime {
|
|
367
395
|
workflowId;
|
|
368
396
|
triggerId;
|
|
369
397
|
envName;
|
|
370
398
|
systemEnvName;
|
|
371
399
|
runtimeUrl;
|
|
400
|
+
logging;
|
|
372
401
|
constructor(opts) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
402
|
+
if (opts instanceof _Runtime) {
|
|
403
|
+
this.workflowId = opts.workflowId;
|
|
404
|
+
this.triggerId = opts.triggerId;
|
|
405
|
+
this.systemEnvName = opts.systemEnvName;
|
|
406
|
+
this.runtimeUrl = opts.runtimeUrl;
|
|
407
|
+
this.envName = opts.envName;
|
|
408
|
+
this.logging = opts.logging || new Logging(this.workflowId, this.triggerId, this.systemEnvName);
|
|
409
|
+
} else {
|
|
410
|
+
this.workflowId = opts.workflowId;
|
|
411
|
+
this.triggerId = opts.triggerId;
|
|
412
|
+
this.systemEnvName = typeof opts.envName !== "undefined" ? opts.envName : (() => {
|
|
413
|
+
const hostId = opts.url.replace(/^(?:https?:)?\/\//i, "").split("/")[0].split(".")[0].toLowerCase();
|
|
414
|
+
let branch = DEFAULT_BRANCH;
|
|
415
|
+
if (hostId.includes("-")) {
|
|
416
|
+
branch = hostId.split("-")[0];
|
|
417
|
+
}
|
|
418
|
+
return branch;
|
|
419
|
+
})();
|
|
420
|
+
this.runtimeUrl = "https://" + new URL("https://" + opts.url.replace(/^(?:https?:)?\/\//i, "").split("/")[0]).host;
|
|
421
|
+
this.envName = this.systemEnvName === DEFAULT_BRANCH ? "prod" : this.systemEnvName;
|
|
422
|
+
this.logging = opts.logging || new Logging(this.workflowId, this.triggerId, this.systemEnvName);
|
|
423
|
+
}
|
|
385
424
|
}
|
|
386
425
|
};
|
|
387
426
|
|
|
@@ -567,13 +606,6 @@ var EnvEngine = class extends Runtime {
|
|
|
567
606
|
};
|
|
568
607
|
}
|
|
569
608
|
async set(envs, level = "trigger", encryptWithValue) {
|
|
570
|
-
const timeout = 300;
|
|
571
|
-
await Promise.race([this.initializeIfNeeded(level), new Promise((resolve, reject) => setTimeout(() => {
|
|
572
|
-
reject(new Error(`Waitied ${timeout}ms. Terminating firestore initialize during the set function`));
|
|
573
|
-
}, timeout))]).catch((err) => {
|
|
574
|
-
console.warn("Invariant: While initializing the env engine during set - " + err.message + ` - ${this.envName} - ${this.workflowId} - ${this.triggerId}.
|
|
575
|
-
Failing quietly as the set might proceed, but this is not a good thing.`);
|
|
576
|
-
});
|
|
577
609
|
let aes = null;
|
|
578
610
|
if (encryptWithValue) {
|
|
579
611
|
aes = new AES256GCM(Buffer.from(encryptWithValue, "utf8"));
|
|
@@ -598,7 +630,6 @@ var EnvEngine = class extends Runtime {
|
|
|
598
630
|
throw new Error(`Failed to set the ${envs.map((x) => x.name).join(", ")}. Error: ${err.message}`);
|
|
599
631
|
}
|
|
600
632
|
}
|
|
601
|
-
Object.assign(this.store[level], obj);
|
|
602
633
|
return void 0;
|
|
603
634
|
}
|
|
604
635
|
async initializeIfNeeded(level = "trigger") {
|
|
@@ -791,7 +822,9 @@ var PubSubHelper = class extends Runtime {
|
|
|
791
822
|
return Promise.all(promises);
|
|
792
823
|
}
|
|
793
824
|
async createOrUpdate(opts) {
|
|
825
|
+
this.logging.log("createOrUpdate called with", opts);
|
|
794
826
|
const [topics] = await this.pubSub.getTopics();
|
|
827
|
+
this.logging.log("topics discovered", topics);
|
|
795
828
|
const infraPrefix = opts.topicName.indexOf("---") !== -1 ? opts.topicName : `${this.envName}---${opts.topicName}`;
|
|
796
829
|
const mainDlqTopicName = `${infraPrefix}-${shortHash(this.triggerId)}-dlq`;
|
|
797
830
|
const tableDlqTopicName = `${infraPrefix}-${shortHash(this.triggerId)}-bq-dlq`;
|
|
@@ -818,11 +851,28 @@ var PubSubHelper = class extends Runtime {
|
|
|
818
851
|
let mainDlqSubscription = mainDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainDlqSubscriptionName) || null;
|
|
819
852
|
let tableSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableSubscriptionName) || null;
|
|
820
853
|
let tableDlqSubscription = tableDlqTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === tableDlqSubscriptionName) || null;
|
|
854
|
+
this.logging.log("environment discovery", {
|
|
855
|
+
mainTopicName: opts.topicName,
|
|
856
|
+
mainDlqTopicName,
|
|
857
|
+
tableDlqTopicName,
|
|
858
|
+
mainSubscriptionName,
|
|
859
|
+
mainDlqSubscriptionName,
|
|
860
|
+
tableSubscriptionName,
|
|
861
|
+
tableDlqSubscriptionName,
|
|
862
|
+
mainTopicExists: mainTopic,
|
|
863
|
+
mainDlqTopicExists: mainDlqTopic,
|
|
864
|
+
tableDlqTopicExists: tableDlqTopic,
|
|
865
|
+
mainSubscriptionExists: mainSubscription,
|
|
866
|
+
mainDlqSubscriptionExists: mainDlqSubscription,
|
|
867
|
+
tableSubscriptionExists: tableSubscription,
|
|
868
|
+
tableDlqSubscriptionExists: tableDlqSubscription
|
|
869
|
+
});
|
|
821
870
|
const topic = await this.ensureTopicExists(opts.topicName);
|
|
822
871
|
if (opts.table || opts.pull || opts.push) {
|
|
823
872
|
mainTopic = await this.ensureTopicExists(opts.topicName);
|
|
824
873
|
}
|
|
825
874
|
if (!opts.table) {
|
|
875
|
+
this.logging.log("createOrUpdate deleting table subscriptions");
|
|
826
876
|
if (tableSubscription) {
|
|
827
877
|
await tableSubscription.delete();
|
|
828
878
|
tableSubscription = null;
|
|
@@ -832,12 +882,17 @@ var PubSubHelper = class extends Runtime {
|
|
|
832
882
|
tableDlqSubscription = null;
|
|
833
883
|
}
|
|
834
884
|
} else {
|
|
885
|
+
this.logging.log("createOrUpdate creating table subscription");
|
|
835
886
|
if (opts.createDeadLetterQueues) {
|
|
887
|
+
this.logging.log("createOrUpdate ensuring dlqs exist for table subscription");
|
|
836
888
|
tableDlqTopic = await this.ensureTopicExists(tableDlqTopicName);
|
|
837
|
-
tableDlqSubscription = await this.
|
|
838
|
-
topic: tableDlqTopic
|
|
889
|
+
tableDlqSubscription = await this.ensureSubscribtionExists(tableDlqSubscriptionName, {
|
|
890
|
+
topic: tableDlqTopic,
|
|
891
|
+
endpointUrl: null,
|
|
892
|
+
dlqTopic: null
|
|
839
893
|
});
|
|
840
894
|
}
|
|
895
|
+
this.logging.log("createOrUpdate ensuring the table subscription exists");
|
|
841
896
|
tableSubscription = await this.ensureSubscribtionExists(tableSubscriptionName, {
|
|
842
897
|
topic,
|
|
843
898
|
tableId: opts.table.tableId,
|
|
@@ -850,6 +905,7 @@ var PubSubHelper = class extends Runtime {
|
|
|
850
905
|
}
|
|
851
906
|
const pullPushSubscription = opts.pull || opts.push;
|
|
852
907
|
if (!pullPushSubscription) {
|
|
908
|
+
this.logging.log("createOrUpdate deleting main subscriptions");
|
|
853
909
|
if (mainSubscription) {
|
|
854
910
|
await mainSubscription.delete();
|
|
855
911
|
mainSubscription = null;
|
|
@@ -860,22 +916,26 @@ var PubSubHelper = class extends Runtime {
|
|
|
860
916
|
}
|
|
861
917
|
} else {
|
|
862
918
|
if (opts.createDeadLetterQueues) {
|
|
919
|
+
this.logging.log("createOrUpdate creating dlqs for main subscription");
|
|
863
920
|
mainDlqTopic = await this.ensureTopicExists(mainDlqTopicName);
|
|
864
|
-
mainDlqSubscription = await this.
|
|
865
|
-
topic: mainDlqTopic
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
topic,
|
|
869
|
-
dlqTopic: mainDlqTopic,
|
|
870
|
-
endpointUrl: opts.push ? this.runtimeUrl + `/executeWorkflow/${this.workflowId}/${this.triggerId}?topic_name=${opts.topicName}` : null,
|
|
871
|
-
retryMinDelay: pullPushSubscription.retryMinDelay,
|
|
872
|
-
retryMaxDelay: pullPushSubscription.retryMaxDelay,
|
|
873
|
-
retryLimit: pullPushSubscription.retryLimit,
|
|
874
|
-
ackDeadline: pullPushSubscription.ackDeadline
|
|
921
|
+
mainDlqSubscription = await this.ensureSubscribtionExists(mainDlqSubscriptionName, {
|
|
922
|
+
topic: mainDlqTopic,
|
|
923
|
+
dlqTopic: null,
|
|
924
|
+
endpointUrl: null
|
|
875
925
|
});
|
|
876
926
|
}
|
|
927
|
+
mainSubscription = await this.ensureSubscribtionExists(mainSubscriptionName, {
|
|
928
|
+
topic,
|
|
929
|
+
dlqTopic: mainDlqTopic || null,
|
|
930
|
+
endpointUrl: opts.push ? this.runtimeUrl + `/executeWorkflow/${this.workflowId}/${this.triggerId}?topic_name=${opts.topicName}` : null,
|
|
931
|
+
retryMinDelay: pullPushSubscription.retryMinDelay,
|
|
932
|
+
retryMaxDelay: pullPushSubscription.retryMaxDelay,
|
|
933
|
+
retryLimit: pullPushSubscription.retryLimit,
|
|
934
|
+
ackDeadline: pullPushSubscription.ackDeadline
|
|
935
|
+
});
|
|
877
936
|
}
|
|
878
937
|
if (!opts.createDeadLetterQueues) {
|
|
938
|
+
this.logging.log("createOrUpdate deleting all dlqs");
|
|
879
939
|
if (mainDlqSubscription) {
|
|
880
940
|
await mainDlqSubscription.delete();
|
|
881
941
|
mainDlqSubscription = null;
|
|
@@ -905,11 +965,20 @@ var PubSubHelper = class extends Runtime {
|
|
|
905
965
|
return topics.find((topic) => this.getNameFromFullyQualifiedName(topic.name) === topicName);
|
|
906
966
|
}
|
|
907
967
|
async ensureTopicExists(topicName) {
|
|
968
|
+
this.logging.log("ensureTopicExists called with", topicName);
|
|
908
969
|
let topic = await this.findTopic(topicName);
|
|
970
|
+
this.logging.log(`ensureTopicExists topic ${!topic ? "does not " : ""}exists`, topic);
|
|
971
|
+
let topicMetadata;
|
|
972
|
+
try {
|
|
973
|
+
[topicMetadata] = await topic?.getMetadata() || [null];
|
|
974
|
+
} catch (err) {
|
|
975
|
+
throw new Error("Invariant: While getting topic metadata - " + err.message);
|
|
976
|
+
}
|
|
977
|
+
this.logging.log(`ensureTopicExists retrieved topic metadata`, topicMetadata);
|
|
909
978
|
const metadata = {
|
|
910
979
|
labels: {
|
|
911
980
|
"created-at": (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
912
|
-
"last-modified-at": (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
981
|
+
"last-modified-at": topicMetadata?.labels?.["last-modified-at"] || (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
913
982
|
"created-by-bs-triggerid": this.triggerId.toLowerCase(),
|
|
914
983
|
"created-by-bs-workflowid": this.workflowId.toLowerCase(),
|
|
915
984
|
"bs-envname": this.systemEnvName.toLowerCase(),
|
|
@@ -917,21 +986,25 @@ var PubSubHelper = class extends Runtime {
|
|
|
917
986
|
[`w-${this.workflowId}-${this.triggerId}`.toLowerCase()]: "true"
|
|
918
987
|
}
|
|
919
988
|
};
|
|
920
|
-
let topicMetadata;
|
|
921
|
-
try {
|
|
922
|
-
[topicMetadata] = await topic?.getMetadata() || [null];
|
|
923
|
-
} catch (err) {
|
|
924
|
-
throw new Error("Invariant: While getting topic metadata - " + err.message);
|
|
925
|
-
}
|
|
926
989
|
if (topic) {
|
|
927
990
|
const simMetadata = Object.assign({}, topicMetadata?.labels || {}, metadata.labels);
|
|
928
991
|
if (!(0, import_lodash.default)(topicMetadata?.labels, simMetadata)) {
|
|
929
992
|
simMetadata["last-modified-at"] = (/* @__PURE__ */ new Date()).getTime().toString();
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
993
|
+
this.logging.log(`ensureTopicExists topic metadata has changed updating with`, simMetadata);
|
|
994
|
+
try {
|
|
995
|
+
await topic.setMetadata({
|
|
996
|
+
labels: simMetadata
|
|
997
|
+
});
|
|
998
|
+
} catch (err) {
|
|
999
|
+
this.logging.error("ensureTopicExists received error while setting metadata", err.message, err.stack);
|
|
1000
|
+
throw err;
|
|
1001
|
+
}
|
|
933
1002
|
}
|
|
934
1003
|
} else {
|
|
1004
|
+
this.logging.log(`ensureTopicExists creating new topic`, {
|
|
1005
|
+
name: topicName,
|
|
1006
|
+
labels: metadata.labels
|
|
1007
|
+
});
|
|
935
1008
|
await this.pubSub.createTopic({
|
|
936
1009
|
name: topicName,
|
|
937
1010
|
labels: metadata.labels
|
|
@@ -954,11 +1027,20 @@ var PubSubHelper = class extends Runtime {
|
|
|
954
1027
|
retryMaxDelay: 360,
|
|
955
1028
|
ackDeadline: 90
|
|
956
1029
|
};
|
|
1030
|
+
this.logging.log("updateSubscription called with", subscriptionName, subscription, subscriptionMetaData, inputOpts);
|
|
957
1031
|
const opts = Object.assign({}, defaultOptions, inputOpts);
|
|
1032
|
+
this.logging.log("updateSubscription final opts", opts);
|
|
958
1033
|
let nextMetadata = null;
|
|
959
1034
|
if (isSubscriptionOptionsPush(opts)) {
|
|
960
1035
|
if (opts.endpointUrl !== subscriptionMetaData?.pushConfig?.pushEndpoint || this.serviceAccountEmail !== subscriptionMetaData?.pushConfig.oidcToken?.serviceAccountEmail || process.env.GCLOUD_PROJECT + "/" + this.triggerId !== subscriptionMetaData.pushConfig.oidcToken.audience) {
|
|
961
1036
|
if (subscriptionMetaData?.pushConfig?.pushEndpoint && subscription) {
|
|
1037
|
+
this.logging.log("updateSubscription pushConfig changed, push configuration already exists, modifying", {
|
|
1038
|
+
pushEndpoint: opts.endpointUrl,
|
|
1039
|
+
oidcToken: {
|
|
1040
|
+
serviceAccountEmail: this.serviceAccountEmail,
|
|
1041
|
+
audience: process.env.GCLOUD_PROJECT + "/" + this.triggerId
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
962
1044
|
try {
|
|
963
1045
|
await subscription.modifyPushConfig({
|
|
964
1046
|
pushEndpoint: opts.endpointUrl,
|
|
@@ -1048,10 +1130,11 @@ var PubSubHelper = class extends Runtime {
|
|
|
1048
1130
|
nextMetadata.bigqueryConfig = null;
|
|
1049
1131
|
}
|
|
1050
1132
|
if (subscription && nextMetadata) {
|
|
1133
|
+
this.logging.log("updateSubscription updating subscription", nextMetadata);
|
|
1051
1134
|
try {
|
|
1052
1135
|
await subscription.setMetadata(nextMetadata);
|
|
1053
1136
|
} catch (err) {
|
|
1054
|
-
|
|
1137
|
+
this.logging.error("updateSubscription received error while setting metadata", err.message, err.stack);
|
|
1055
1138
|
throw new Error("Invariant: While updating subscription - " + err.message);
|
|
1056
1139
|
}
|
|
1057
1140
|
}
|
|
@@ -1060,14 +1143,17 @@ var PubSubHelper = class extends Runtime {
|
|
|
1060
1143
|
async ensureSubscribtionExists(subscriptionName, opts) {
|
|
1061
1144
|
let [subscriptions] = await opts.topic.getSubscriptions();
|
|
1062
1145
|
let subscription = subscriptions.find((subscription2) => this.getNameFromFullyQualifiedName(subscription2.name) === subscriptionName) || null;
|
|
1146
|
+
this.logging.log("ensureSubscribtionExists called with", subscriptionName, opts);
|
|
1063
1147
|
let subscriptionMetaData;
|
|
1064
1148
|
try {
|
|
1065
1149
|
[subscriptionMetaData] = await subscription?.getMetadata() || [null];
|
|
1066
1150
|
} catch (err) {
|
|
1067
1151
|
throw new Error("Invariant: While getting subscription metadata - " + err.message);
|
|
1068
1152
|
}
|
|
1153
|
+
this.logging.log("ensureSubscribtionExists retrieved subscriptionMetaData", subscriptionMetaData);
|
|
1069
1154
|
const createPayload = await this.updateSubscription(subscriptionName, subscription, subscriptionMetaData, opts);
|
|
1070
|
-
if (createPayload) {
|
|
1155
|
+
if (createPayload && !subscription) {
|
|
1156
|
+
this.logging.log(`ensureSubscribtionExists creating subscription: ${subscriptionName} on topic: ${opts.topic.name} with`, createPayload);
|
|
1071
1157
|
await opts.topic.createSubscription(subscriptionName, createPayload);
|
|
1072
1158
|
[subscriptions] = await opts.topic.getSubscriptions();
|
|
1073
1159
|
subscription = subscriptions.find((subscription2) => this.getNameFromFullyQualifiedName(subscription2.name) === subscriptionName) || null;
|
|
@@ -1077,20 +1163,8 @@ var PubSubHelper = class extends Runtime {
|
|
|
1077
1163
|
}
|
|
1078
1164
|
return subscription;
|
|
1079
1165
|
}
|
|
1080
|
-
async ensureDLQSubscriptionExists(subscriptionName, opts) {
|
|
1081
|
-
let [subscriptions] = await opts.topic.getSubscriptions();
|
|
1082
|
-
let subscription = subscriptions.find((subscription2) => this.getNameFromFullyQualifiedName(subscription2.name) === subscriptionName);
|
|
1083
|
-
if (!subscription) {
|
|
1084
|
-
await opts.topic.createSubscription(subscriptionName);
|
|
1085
|
-
[subscriptions] = await opts.topic.getSubscriptions();
|
|
1086
|
-
subscription = subscriptions.find((subscription2) => this.getNameFromFullyQualifiedName(subscription2.name) === subscriptionName);
|
|
1087
|
-
}
|
|
1088
|
-
if (!subscription) {
|
|
1089
|
-
throw new Error(`Invariant: While creating subscription - subscription is not found`);
|
|
1090
|
-
}
|
|
1091
|
-
return subscription;
|
|
1092
|
-
}
|
|
1093
1166
|
async deleteSubscriptions(topicName) {
|
|
1167
|
+
this.logging.log("deleteSubscriptions called with", topicName);
|
|
1094
1168
|
return this.createOrUpdate({
|
|
1095
1169
|
topicName,
|
|
1096
1170
|
createDeadLetterQueues: false,
|
|
@@ -1102,14 +1176,18 @@ var PubSubHelper = class extends Runtime {
|
|
|
1102
1176
|
async isRunning(topicName) {
|
|
1103
1177
|
const [topics] = await this.pubSub.getTopics();
|
|
1104
1178
|
const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
|
|
1179
|
+
this.logging.log("isRunning called with", topicName);
|
|
1105
1180
|
const infraPrefix = topicName.indexOf("---") !== -1 ? topicName : `${this.envName}---${topicName}`;
|
|
1106
1181
|
let mainTopicSubscriptions = null;
|
|
1107
1182
|
if (mainTopic) {
|
|
1108
1183
|
[mainTopicSubscriptions] = await mainTopic.getSubscriptions();
|
|
1109
1184
|
}
|
|
1110
1185
|
const mainSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}`;
|
|
1186
|
+
this.logging.log("isRunning checking the", mainSubscriptionName);
|
|
1111
1187
|
const mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
|
|
1188
|
+
this.logging.log("isRunning found the", mainSubscription);
|
|
1112
1189
|
const [metadata] = await mainSubscription?.getMetadata() || [null];
|
|
1190
|
+
this.logging.log("isRunning received metadata", metadata);
|
|
1113
1191
|
return {
|
|
1114
1192
|
subscriptionId: mainSubscription?.name,
|
|
1115
1193
|
isRunning: metadata?.pushConfig?.pushEndpoint !== null
|
|
@@ -1118,17 +1196,25 @@ var PubSubHelper = class extends Runtime {
|
|
|
1118
1196
|
async pause(topicName) {
|
|
1119
1197
|
const [topics] = await this.pubSub.getTopics();
|
|
1120
1198
|
const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
|
|
1199
|
+
this.logging.log("paused called with", topicName);
|
|
1121
1200
|
const infraPrefix = topicName.indexOf("---") !== -1 ? topicName : `${this.envName}---${topicName}`;
|
|
1122
1201
|
let mainTopicSubscriptions = null;
|
|
1123
1202
|
if (mainTopic) {
|
|
1124
1203
|
[mainTopicSubscriptions] = await mainTopic.getSubscriptions();
|
|
1125
1204
|
}
|
|
1126
1205
|
const mainSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}`;
|
|
1206
|
+
this.logging.log("isRunning checking the", mainSubscriptionName);
|
|
1127
1207
|
const mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
|
|
1208
|
+
this.logging.log("pause found the", mainSubscription);
|
|
1128
1209
|
if (mainSubscription) {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1210
|
+
try {
|
|
1211
|
+
await mainSubscription.setMetadata({
|
|
1212
|
+
pushConfig: null
|
|
1213
|
+
});
|
|
1214
|
+
} catch (err) {
|
|
1215
|
+
this.logging.error("pause received error while setting metadata", err.message, err.stack);
|
|
1216
|
+
throw err;
|
|
1217
|
+
}
|
|
1132
1218
|
return {
|
|
1133
1219
|
subscriptionId: mainSubscription.name
|
|
1134
1220
|
};
|
|
@@ -1140,23 +1226,40 @@ var PubSubHelper = class extends Runtime {
|
|
|
1140
1226
|
async resume(topicName) {
|
|
1141
1227
|
const [topics] = await this.pubSub.getTopics();
|
|
1142
1228
|
const mainTopic = topics.find((x) => this.getNameFromFullyQualifiedName(x.name) === topicName);
|
|
1229
|
+
this.logging.log("resume called with", topicName);
|
|
1143
1230
|
const infraPrefix = topicName.indexOf("---") !== -1 ? topicName : `${this.envName}---${topicName}`;
|
|
1144
1231
|
let mainTopicSubscriptions = null;
|
|
1145
1232
|
if (mainTopic) {
|
|
1146
1233
|
[mainTopicSubscriptions] = await mainTopic.getSubscriptions();
|
|
1147
1234
|
}
|
|
1148
1235
|
const mainSubscriptionName = `${infraPrefix}-${shortHash(this.triggerId)}`;
|
|
1236
|
+
this.logging.log("resume checking the", mainSubscriptionName);
|
|
1149
1237
|
const mainSubscription = mainTopicSubscriptions?.find((x) => this.getNameFromFullyQualifiedName(x.name) === mainSubscriptionName) || null;
|
|
1238
|
+
this.logging.log("resume found the", mainSubscription);
|
|
1150
1239
|
if (mainSubscription) {
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1240
|
+
try {
|
|
1241
|
+
this.logging.log("resume setting metadata", {
|
|
1242
|
+
pushConfig: {
|
|
1243
|
+
pushEndpoint: this.runtimeUrl + "/executeWorkflow/" + this.workflowId + "/" + this.triggerId + `?topic_name=${topicName}`,
|
|
1244
|
+
oidcToken: {
|
|
1245
|
+
serviceAccountEmail: this.serviceAccountEmail,
|
|
1246
|
+
audience: process.env.GCLOUD_PROJECT + "/" + this.triggerId
|
|
1247
|
+
}
|
|
1157
1248
|
}
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1249
|
+
});
|
|
1250
|
+
await mainSubscription.setMetadata({
|
|
1251
|
+
pushConfig: {
|
|
1252
|
+
pushEndpoint: this.runtimeUrl + "/executeWorkflow/" + this.workflowId + "/" + this.triggerId + `?topic_name=${topicName}`,
|
|
1253
|
+
oidcToken: {
|
|
1254
|
+
serviceAccountEmail: this.serviceAccountEmail,
|
|
1255
|
+
audience: process.env.GCLOUD_PROJECT + "/" + this.triggerId
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
} catch (err) {
|
|
1260
|
+
this.logging.error("resume received error while setting metadata", err.message, err.stack);
|
|
1261
|
+
throw err;
|
|
1262
|
+
}
|
|
1160
1263
|
return {
|
|
1161
1264
|
subscriptionId: mainSubscription.name
|
|
1162
1265
|
};
|