MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / deleteOldTopics

Function deleteOldTopics

dlp/system-test/risk.test.js:58–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56 });
57
58 async function deleteOldTopics() {
59 const [topics] = await pubsub.getTopics();
60 const now = Date.now();
61 const TEN_HOURS_MS = 1000 * 60 * 60 * 10;
62 for (const topic of topics) {
63 const created = Number(topic.name.split('-').pop());
64 if (
65 topic.name.includes('dlp-risk-topic') &&
66 now - created > TEN_HOURS_MS
67 ) {
68 const [subscriptions] = await topic.getSubscriptions();
69 for (const subscription of subscriptions) {
70 console.info(`deleting ${subscription.name}`);
71 await subscription.delete();
72 }
73 console.info(`deleting ${topic.name}`);
74 await topic.delete();
75 }
76 }
77 }
78
79 // Delete custom topic/subscription
80 after(async () => {

Callers 1

risk.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected