@cap-js-community/event-queue
Advanced tools
Comparing version 1.2.4 to 1.2.5
{ | ||
"name": "@cap-js-community/event-queue", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "An event queue that enables secure transactional processing of asynchronous and periodic events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.", | ||
@@ -52,11 +52,11 @@ "main": "src/index.js", | ||
"@sap/cds-dk": "^7.5.1", | ||
"eslint": "8.56.0", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-plugin-jest": "27.6.3", | ||
"eslint-plugin-node": "11.1.0", | ||
"express": "4.18.2", | ||
"hdb": "0.19.7", | ||
"jest": "29.7.0", | ||
"prettier": "2.8.8", | ||
"sqlite3": "5.1.7" | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-jest": "^27.6.3", | ||
"eslint-plugin-node": "^11.1.0", | ||
"express": "^4.18.2", | ||
"hdb": "^0.19.7", | ||
"jest": "^29.7.0", | ||
"prettier": "^2.8.8", | ||
"sqlite3": "^5.1.7" | ||
}, | ||
@@ -63,0 +63,0 @@ "homepage": "https://cap-js-community.github.io/event-queue/", |
@@ -31,3 +31,2 @@ # @cap-js-community/event-queue | ||
"eventQueue": { | ||
"plugin": true, | ||
"configFilePath": "./srv/eventQueueConfig.yml" | ||
@@ -34,0 +33,0 @@ } |
@@ -60,2 +60,3 @@ "use strict"; | ||
#enableTxConsistencyCheck; | ||
#cleanupLocksAndEventsForDev; | ||
static #instance; | ||
@@ -344,2 +345,5 @@ constructor() { | ||
set runInterval(value) { | ||
if (!Number.isInteger(value) || value <= 10 * 1000) { | ||
throw EventQueueError.invalidInterval(); | ||
} | ||
this.#runInterval = value; | ||
@@ -476,2 +480,10 @@ } | ||
set cleanupLocksAndEventsForDev(value) { | ||
this.#cleanupLocksAndEventsForDev = value; | ||
} | ||
get cleanupLocksAndEventsForDev() { | ||
return this.#cleanupLocksAndEventsForDev; | ||
} | ||
get isMultiTenancy() { | ||
@@ -478,0 +490,0 @@ return !!cds.requires.multitenancy; |
@@ -17,2 +17,4 @@ "use strict"; | ||
const eventQueueAsOutbox = require("./outbox/eventQueueAsOutbox"); | ||
const { getAllTenantIds } = require("./shared/cdsHelper"); | ||
const { EventProcessingStatus } = require("./constants"); | ||
@@ -42,2 +44,3 @@ const readFileAsync = promisify(fs.readFile); | ||
["enableTxConsistencyCheck", false], | ||
["registerCleanupForDev", true], | ||
]; | ||
@@ -60,7 +63,4 @@ | ||
enableTxConsistencyCheck, | ||
cleanupLocksAndEventsForDev, | ||
} = {}) => { | ||
// TODO: initialize check: | ||
// - content of yaml check | ||
// - betweenRuns | ||
if (config.initialized) { | ||
@@ -85,3 +85,4 @@ return; | ||
userId, | ||
enableTxConsistencyCheck | ||
enableTxConsistencyCheck, | ||
cleanupLocksAndEventsForDev | ||
); | ||
@@ -97,2 +98,3 @@ | ||
dbHandler.registerEventQueueDbHandler(service); | ||
config.cleanupLocksAndEventsForDev && registerCleanupForDevDb().catch(() => {}); | ||
} | ||
@@ -116,16 +118,24 @@ }); | ||
const readConfigFromFile = async (configFilepath) => { | ||
const fileData = await readFileAsync(configFilepath); | ||
if (/\.ya?ml$/i.test(configFilepath)) { | ||
return yaml.parse(fileData.toString()); | ||
try { | ||
const fileData = await readFileAsync(configFilepath); | ||
if (/\.ya?ml$/i.test(configFilepath)) { | ||
return yaml.parse(fileData.toString()); | ||
} | ||
if (/\.json$/i.test(configFilepath)) { | ||
return JSON.parse(fileData.toString()); | ||
} | ||
throw new VError( | ||
{ | ||
name: VERROR_CLUSTER_NAME, | ||
info: { configFilepath }, | ||
}, | ||
"configFilepath with unsupported extension, allowed extensions are .yaml and .json" | ||
); | ||
} catch (err) { | ||
if (config.useAsCAPOutbox) { | ||
return {}; | ||
} | ||
throw err; | ||
} | ||
if (/\.json$/i.test(configFilepath)) { | ||
return JSON.parse(fileData.toString()); | ||
} | ||
throw new VError( | ||
{ | ||
name: VERROR_CLUSTER_NAME, | ||
info: { configFilepath }, | ||
}, | ||
"configFilepath with unsupported extension, allowed extensions are .yaml and .json" | ||
); | ||
}; | ||
@@ -158,5 +168,7 @@ | ||
get: () => eventQueueAsOutbox.outboxed, | ||
configurable: true, | ||
}); | ||
Object.defineProperty(cds, "unboxed", { | ||
get: () => eventQueueAsOutbox.unboxed, | ||
configurable: true, | ||
}); | ||
@@ -223,4 +235,23 @@ } | ||
const registerCleanupForDevDb = async () => { | ||
const profile = cds.env.profiles.find((profile) => profile === "development"); | ||
if (!profile) { | ||
return; | ||
} | ||
const tenantIds = await getAllTenantIds(); | ||
for (const tenantId of tenantIds) { | ||
await cds.tx({ tenant: tenantId }, async (tx) => { | ||
await tx.run(DELETE.from(config.tableNameEventLock)); | ||
await tx.run( | ||
UPDATE.entity(config.tableNameEventQueue).where({ status: EventProcessingStatus.InProgress }).set({ | ||
status: EventProcessingStatus.Error, | ||
}) | ||
); | ||
}); | ||
} | ||
}; | ||
module.exports = { | ||
initialize, | ||
}; |
154797
3774
73