@shushed/helpers 0.0.257 → 0.0.258
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.
|
@@ -436,6 +436,21 @@ class PubSubHelper extends runtime_1.default {
|
|
|
436
436
|
async ensureSubscribtionExists(subscriptionName, opts) {
|
|
437
437
|
let [subscriptions] = await opts.topic.getSubscriptions();
|
|
438
438
|
let subscription = subscriptions.find((subscription) => this.getNameFromFullyQualifiedName(subscription.name) === subscriptionName) || null;
|
|
439
|
+
if (!subscription) {
|
|
440
|
+
const existingSub = this.pubSub.subscription(subscriptionName);
|
|
441
|
+
try {
|
|
442
|
+
const [existingMetadata] = await existingSub.getMetadata();
|
|
443
|
+
if (existingMetadata && existingMetadata.topic !== opts.topic.name) {
|
|
444
|
+
this.logging.log(`ensureSubscribtionExists: subscription ${subscriptionName} exists on different topic (${existingMetadata.topic}), deleting to recreate on ${opts.topic.name}`);
|
|
445
|
+
await existingSub.delete();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
if (err.code !== 5) {
|
|
450
|
+
throw err;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
439
454
|
let subscriptionMetaData;
|
|
440
455
|
try {
|
|
441
456
|
[subscriptionMetaData] = (await subscription?.getMetadata()) || [null];
|