Skip to content

Commit 0e8b9d6

Browse files
committed
Update store-cleanup-job.js
Adjusted the store cleanup so it now also clears out cases that have arrived via the socket interface, which has a different prefix - `c:`.
1 parent d28cdeb commit 0e8b9d6

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

app/job/store-cleanup-job.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const redis = require('../redis/redis-client');
66
const { logPipelineFailures } = redis;
77
const REDIS_ACTIVITY_KEY_PREFIX = config.get('redis.keyPrefix');
88

9-
const scanExistingCasesKeys = (f) => {
9+
const scanExistingCasesKeys = (f, prefix) => {
1010
const stream = redis.scanStream({
1111
// only returns keys following the pattern
12-
match: `${REDIS_ACTIVITY_KEY_PREFIX}case:*`,
12+
match: `${REDIS_ACTIVITY_KEY_PREFIX}${prefix}:*`,
1313
// returns approximately 100 elements per call
1414
count: 100,
1515
});
@@ -26,7 +26,7 @@ const scanExistingCasesKeys = (f) => {
2626
});
2727
};
2828

29-
const getCasesWithActivities = (f) => scanExistingCasesKeys(f);
29+
const getCasesWithActivities = (f, prefix) => scanExistingCasesKeys(f, prefix);
3030

3131
const cleanupActivitiesCommand = (key) => ['zremrangebyscore', key, '-inf', Date.now()];
3232

@@ -38,6 +38,11 @@ const pipeline = (cases) => {
3838

3939
const storeCleanup = () => {
4040
debug('store cleanup starting...');
41+
cleanCasesWithPrefix('case'); // Cases via RESTful interface.
42+
cleanCasesWithPrefix('c'); // Cases via socket interface.
43+
};
44+
45+
const cleanCasesWithPrefix = (prefix) => {
4146
getCasesWithActivities((cases) => {
4247
// scan returns the prefixed keys. Remove them since the redis client will add it back
4348
const casesWithoutPrefix = cases.map((k) => k.replace(REDIS_ACTIVITY_KEY_PREFIX, ''));
@@ -48,7 +53,7 @@ const storeCleanup = () => {
4853
.catch((err) => {
4954
debug('Error in getCasesWithActivities', err.message);
5055
});
51-
});
56+
}, prefix);
5257
};
5358

5459
exports.start = (crontab) => {

0 commit comments

Comments
 (0)