@bonniernews/b0rker
Advanced tools
Comparing version 7.2.0 to 7.3.0
@@ -52,2 +52,3 @@ import express from "express"; | ||
/* c8 ignore start */ | ||
if (startServer) { | ||
@@ -59,4 +60,5 @@ const port = process.env.PORT || 8080; | ||
} | ||
/* c8 ignore stop */ | ||
return app; | ||
} |
@@ -78,6 +78,6 @@ import { Firestore } from "@google-cloud/firestore"; | ||
let completedJobs = []; | ||
const completedJobs = new Set(); | ||
for (const doc of querySnapshot.docs) { | ||
const theseCompletedJobs = doc.get("completedJobs"); | ||
completedJobs = [ ...new Set([ ...theseCompletedJobs, ...completedJobs ]) ]; | ||
theseCompletedJobs.forEach((job) => completedJobs.add(job)); | ||
} | ||
@@ -89,7 +89,12 @@ return completedJobs; | ||
const logger = buildLogger(parentCorrelationId, "removeParent"); | ||
let res; | ||
try { | ||
const res = await db.runTransaction(async (t) => { | ||
res = await db.runTransaction(async (t) => { | ||
// remove the parent document from the processed collection | ||
const parentDoc = await db.collection("processed").doc(parentCorrelationId).get(); | ||
await t.delete(parentDoc.ref); | ||
if (!parentDoc.exists) { | ||
logger.warn(`Parent ${parentCorrelationId} not found, it has probably been deleted already. Exiting.`); | ||
return false; | ||
} | ||
t.delete(parentDoc.ref); | ||
@@ -103,4 +108,4 @@ // when deleting a collection, the recommendation from Google is to delete in batches, | ||
}); | ||
return true; | ||
}); | ||
return res; | ||
} catch (e) { | ||
@@ -110,2 +115,3 @@ logger.error(`Remove parent failed ${e}`); | ||
} | ||
return res; | ||
} | ||
@@ -112,0 +118,0 @@ |
@@ -79,3 +79,3 @@ // we try and copy the functionality of firestore here as best we can | ||
// we don't delete anything in the memory store, since we want the data to be available for testing | ||
return; | ||
return true; | ||
} | ||
@@ -82,0 +82,0 @@ |
@@ -43,2 +43,4 @@ import config from "exp-config"; | ||
logger.info(`incoming message ${JSON.stringify(messageData)}`); | ||
const handleError = async (error) => { | ||
@@ -102,3 +104,3 @@ if (error.rejected) { | ||
} catch (err) { | ||
logger.error(`Firebase error: ${JSON.stringify(err)}`); | ||
logger.error(`Firestore error: ${err.code} ${err.message}`); | ||
return res.status(502).send({ error: err }); | ||
@@ -109,3 +111,2 @@ } | ||
logger.info(`incoming message ${JSON.stringify(messageData)}`); | ||
const parts = key.split("."); | ||
@@ -202,3 +203,12 @@ const suffix = parts.pop(); | ||
if (isLast) { | ||
await jobStorage.removeParent(parentCorrelationId); | ||
const removedParent = await jobStorage.removeParent(parentCorrelationId); | ||
if (!removedParent) { | ||
logger.warn( | ||
`sub-sequence ${key} finished but parent ${parentCorrelationId} is already removed, probably due to ` | ||
+ "multiple sub-sequences finishing at the same time. Main sequence continuation should already have " | ||
+ "been triggered, exiting." | ||
); | ||
return res.status(200).send(); | ||
} | ||
await publishMessage( | ||
@@ -205,0 +215,0 @@ { ...parentData.message, data: [ ...parentData.message.data, { type: key, id: completedJobCount } ] }, |
@@ -12,3 +12,3 @@ import { PubSub } from "@google-cloud/pubsub"; | ||
export default async function publishMessage(message, attributes) { | ||
const logger = buildLogger(message.correlationId); | ||
const logger = buildLogger(attributes.correlationId); | ||
const messageId = await publishPubsubMessage( | ||
@@ -23,3 +23,3 @@ pubSubClient.topic(config.topic), | ||
export async function rejectMessage(message, attributes) { | ||
const logger = buildLogger(message.correlationId); | ||
const logger = buildLogger(attributes.correlationId); | ||
const messageId = await publishPubsubMessage( | ||
@@ -26,0 +26,0 @@ pubSubClient.topic(config.deadLetterTopic), |
{ | ||
"name": "@bonniernews/b0rker", | ||
"version": "7.2.0", | ||
"version": "7.3.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=16" |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
165055
4417
1