Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while ( archiverCount > 0 ) {
- messages
- .find( )
- .where('state').equals('REMOTE')
- .where('is_spam').equals(false)
- .where('spam_score').lte(MAX_SPAM_SCORE)
- .where('deliveryAttempts').lte(MAX_DELIVERY_ATTEMPTS)
- .where('nextDeliverAttempt').equals(null)
- .sort( ARCHIVE_SORT )
- .exec( )
- .then( async (msgDoc) => {
- if ( msgDoc === null || msgDoc === undefined ) {
- log.error('msgDoc provided in .then() is NULL!');
- console.error('[' + getTimestamp() + '] msgDoc provided in .then() is NULL!');
- // By calling return this early in the async function, we're essentially calling
- // 'continue' to iterate through the while() loop again.
- return false;
- }
- console.debug('msgDoc (inside while() loop): ' + JSON.stringify(msgDoc));
- logEntry = '[' + getTimestamp() + '] Beginning message archival process (id: ' + msgDoc._id + ').';
- //
- // W-T-F ??
- // The call to console.debug() that references 'msgDoc' /sees/ the document and all of
- // it's properties; but then by the /very next/ line, accessing one of those properties
- // (the '_id' property) returns undefined.
- //
- console.debug(logEntry);
- console.debug('msgDoc: ' + JSON.stringify(msgDoc));
- console.debug('msgDoc._id: ' + msgDoc._id);
- res = await messages
- .updateOne({'_id': msgDoc._id},
- {
- '$push': { 'Log': logEntry },
- '$currentDate': { 'lastUpdated': { '$type': 'date' }}
- })
- .exec();
- if ( res.modifiedCount != 1 ) {
- // modifiedCount should NEVER be greater than 1 (since we called findOne()
- // nor should it ever be zero; in either case, something is awry.
- console.log('[' + getTimestamp() + '] messages.updateOne() modified count != 1: ' +
- res.modifiedCount + '.');
- log.info('[' + getTimestamp() + '] messages.updateOne() modified count != 1: ' +
- res.modifiedCount + '.');
- dbLog.create({
- 'application': APP_NAME_FULL,
- 'ts': Date.now(),
- 'host': fqdn,
- 'pid': process.pid,
- 'message': 'messages.updateOne() modified count != 1 (value: ' + res.modifiedCount + ')'
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment