mongochangestream
Advanced tools
Comparing version 0.29.0 to 0.30.0
@@ -0,1 +1,7 @@ | ||
# 0.30.0 | ||
- Fixed bug preventing a previously completed initial scan from being stopped once restarted. | ||
- Renamed `maintainHealth` to `enableHealthCheck`. | ||
- Health check only emits now. You must call `restart` manually to reproduce the previous behavior. | ||
# 0.29.0 | ||
@@ -2,0 +8,0 @@ |
@@ -80,6 +80,6 @@ "use strict"; | ||
*/ | ||
const maintainHealth = (healthCheckInterval = (0, ms_1.default)('1m')) => { | ||
const healthChecker = (healthCheckInterval = (0, ms_1.default)('1m')) => { | ||
let timer; | ||
let stopped; | ||
const checkHealth = async () => { | ||
const runHealthCheck = async () => { | ||
debug('Checking health - initial scan'); | ||
@@ -94,3 +94,2 @@ const lastHealthCheck = new Date().getTime() - healthCheckInterval; | ||
emit('healthCheckFail', { initialScan: true, lastSyncedAt }); | ||
restart(); | ||
} | ||
@@ -101,3 +100,3 @@ }; | ||
stopped = false; | ||
timer = setInterval(checkHealth, healthCheckInterval); | ||
timer = setInterval(runHealthCheck, healthCheckInterval); | ||
}; | ||
@@ -111,3 +110,3 @@ const stop = () => { | ||
}; | ||
const healthCheck = maintainHealth(options.healthCheckInterval); | ||
const healthCheck = healthChecker(options.healthCheckInterval); | ||
const start = async () => { | ||
@@ -125,6 +124,8 @@ debug('Starting initial scan'); | ||
debug(`Initial scan previously completed on %s`, scanCompleted); | ||
// Exit | ||
// We're done | ||
deferred.done(); | ||
return; | ||
} | ||
if (options.maintainHealth) { | ||
// Start the health check | ||
if (options.enableHealthCheck) { | ||
healthCheck.start(); | ||
@@ -185,2 +186,3 @@ } | ||
await cursor?.close(); | ||
debug('MongoDB cursor closed'); | ||
// Wait for start fn to finish | ||
@@ -206,6 +208,6 @@ await deferred?.promise; | ||
*/ | ||
const maintainHealth = (healthCheckInterval = (0, ms_1.default)('1m')) => { | ||
const healthChecker = (healthCheckInterval = (0, ms_1.default)('1m')) => { | ||
let timer; | ||
let stopped; | ||
const checkHealth = async () => { | ||
const runHealthCheck = async () => { | ||
debug('Checking health - change stream'); | ||
@@ -220,5 +222,5 @@ const lastHealthCheck = new Date().getTime() - healthCheckInterval; | ||
const withinHealthCheck = (x) => x && x > lastHealthCheck; | ||
// A record was created within the health check window but not synced | ||
// A record was created within the health check window but not synced. | ||
// NOTE: It is possible for a record to be created a the end of the window | ||
// but not synced before the next health check leading to an unnecessary restart. | ||
// but not synced before the next health check leading to a false failure. | ||
if (withinHealthCheck(lastRecordCreatedAt) && | ||
@@ -233,3 +235,2 @@ !withinHealthCheck(lastSyncedAt) && | ||
}); | ||
restart(); | ||
} | ||
@@ -240,3 +241,3 @@ }; | ||
stopped = false; | ||
timer = setInterval(checkHealth, healthCheckInterval); | ||
timer = setInterval(runHealthCheck, healthCheckInterval); | ||
}; | ||
@@ -250,3 +251,3 @@ const stop = () => { | ||
}; | ||
const healthCheck = maintainHealth(options.healthCheckInterval); | ||
const healthCheck = healthChecker(options.healthCheckInterval); | ||
const start = async () => { | ||
@@ -267,3 +268,3 @@ debug('Starting change stream'); | ||
// Start the health check | ||
if (options.maintainHealth) { | ||
if (options.enableHealthCheck) { | ||
healthCheck.start(); | ||
@@ -294,4 +295,6 @@ } | ||
await changeStream?.close(); | ||
debug('MongoDB change stream closed'); | ||
// Wait for start fn to finish | ||
await deferred?.promise; | ||
debug('Stopped change stream'); | ||
}; | ||
@@ -306,2 +309,3 @@ const restart = async () => { | ||
const reset = async () => { | ||
debug('Reset'); | ||
await redis.del(...Object.values(keys)); | ||
@@ -308,0 +312,0 @@ }; |
@@ -10,3 +10,3 @@ import { ChangeStreamDocument, ChangeStreamInsertDocument, Document } from 'mongodb'; | ||
/** Set to true to run a health check in the background. */ | ||
maintainHealth?: boolean; | ||
enableHealthCheck?: boolean; | ||
/** How often to run the health check. */ | ||
@@ -22,3 +22,3 @@ healthCheckInterval?: number; | ||
/** Set to true to run a health check in the background. */ | ||
maintainHealth?: boolean; | ||
enableHealthCheck?: boolean; | ||
/** How often to run the health check. */ | ||
@@ -25,0 +25,0 @@ healthCheckInterval?: number; |
{ | ||
"name": "mongochangestream", | ||
"version": "0.29.0", | ||
"version": "0.30.0", | ||
"description": "Sync MongoDB collections via change streams into any database.", | ||
@@ -5,0 +5,0 @@ "author": "GovSpend", |
@@ -116,7 +116,7 @@ import _ from 'lodash/fp.js' | ||
*/ | ||
const maintainHealth = (healthCheckInterval = ms('1m')) => { | ||
const healthChecker = (healthCheckInterval = ms('1m')) => { | ||
let timer: NodeJS.Timer | ||
let stopped: boolean | ||
const checkHealth = async () => { | ||
const runHealthCheck = async () => { | ||
debug('Checking health - initial scan') | ||
@@ -131,3 +131,2 @@ const lastHealthCheck = new Date().getTime() - healthCheckInterval | ||
emit('healthCheckFail', { initialScan: true, lastSyncedAt }) | ||
restart() | ||
} | ||
@@ -138,3 +137,3 @@ } | ||
stopped = false | ||
timer = setInterval(checkHealth, healthCheckInterval) | ||
timer = setInterval(runHealthCheck, healthCheckInterval) | ||
} | ||
@@ -149,3 +148,3 @@ const stop = () => { | ||
const healthCheck = maintainHealth(options.healthCheckInterval) | ||
const healthCheck = healthChecker(options.healthCheckInterval) | ||
@@ -164,6 +163,8 @@ const start = async () => { | ||
debug(`Initial scan previously completed on %s`, scanCompleted) | ||
// Exit | ||
// We're done | ||
deferred.done() | ||
return | ||
} | ||
if (options.maintainHealth) { | ||
// Start the health check | ||
if (options.enableHealthCheck) { | ||
healthCheck.start() | ||
@@ -234,2 +235,3 @@ } | ||
await cursor?.close() | ||
debug('MongoDB cursor closed') | ||
// Wait for start fn to finish | ||
@@ -263,7 +265,7 @@ await deferred?.promise | ||
*/ | ||
const maintainHealth = (healthCheckInterval = ms('1m')) => { | ||
const healthChecker = (healthCheckInterval = ms('1m')) => { | ||
let timer: NodeJS.Timer | ||
let stopped: boolean | ||
const checkHealth = async () => { | ||
const runHealthCheck = async () => { | ||
debug('Checking health - change stream') | ||
@@ -278,5 +280,5 @@ const lastHealthCheck = new Date().getTime() - healthCheckInterval | ||
const withinHealthCheck = (x?: number) => x && x > lastHealthCheck | ||
// A record was created within the health check window but not synced | ||
// A record was created within the health check window but not synced. | ||
// NOTE: It is possible for a record to be created a the end of the window | ||
// but not synced before the next health check leading to an unnecessary restart. | ||
// but not synced before the next health check leading to a false failure. | ||
if ( | ||
@@ -293,3 +295,2 @@ withinHealthCheck(lastRecordCreatedAt) && | ||
}) | ||
restart() | ||
} | ||
@@ -300,3 +301,3 @@ } | ||
stopped = false | ||
timer = setInterval(checkHealth, healthCheckInterval) | ||
timer = setInterval(runHealthCheck, healthCheckInterval) | ||
} | ||
@@ -311,3 +312,3 @@ const stop = () => { | ||
const healthCheck = maintainHealth(options.healthCheckInterval) | ||
const healthCheck = healthChecker(options.healthCheckInterval) | ||
@@ -332,3 +333,3 @@ const start = async () => { | ||
// Start the health check | ||
if (options.maintainHealth) { | ||
if (options.enableHealthCheck) { | ||
healthCheck.start() | ||
@@ -365,4 +366,6 @@ } | ||
await changeStream?.close() | ||
debug('MongoDB change stream closed') | ||
// Wait for start fn to finish | ||
await deferred?.promise | ||
debug('Stopped change stream') | ||
} | ||
@@ -380,2 +383,3 @@ | ||
const reset = async () => { | ||
debug('Reset') | ||
await redis.del(...Object.values(keys)) | ||
@@ -382,0 +386,0 @@ } |
@@ -20,3 +20,3 @@ import { | ||
/** Set to true to run a health check in the background. */ | ||
maintainHealth?: boolean | ||
enableHealthCheck?: boolean | ||
/** How often to run the health check. */ | ||
@@ -33,3 +33,3 @@ healthCheckInterval?: number | ||
/** Set to true to run a health check in the background. */ | ||
maintainHealth?: boolean | ||
enableHealthCheck?: boolean | ||
/** How often to run the health check. */ | ||
@@ -36,0 +36,0 @@ healthCheckInterval?: number |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54812
1215
59
3
4
0
13