-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed email retention, improved locking and email processing, fi…
…xed pagination api bug, cleanup denylist issues
- Loading branch information
Showing
12 changed files
with
131 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// eslint-disable-next-line import/no-unassigned-import | ||
require('#config/env'); | ||
|
||
const process = require('process'); | ||
const { parentPort } = require('worker_threads'); | ||
|
||
// eslint-disable-next-line import/no-unassigned-import | ||
require('#config/mongoose'); | ||
|
||
const Graceful = require('@ladjs/graceful'); | ||
const ms = require('ms'); | ||
const parseErr = require('parse-err'); | ||
|
||
const mongoose = require('mongoose'); | ||
const emailHelper = require('#helpers/email'); | ||
const Emails = require('#models/emails'); | ||
const logger = require('#helpers/logger'); | ||
const config = require('#config'); | ||
const setupMongoose = require('#helpers/setup-mongoose'); | ||
|
||
const graceful = new Graceful({ | ||
mongooses: [mongoose], | ||
logger | ||
}); | ||
|
||
graceful.listen(); | ||
|
||
(async () => { | ||
await setupMongoose(logger); | ||
|
||
try { | ||
await Emails.deleteMany( | ||
{ | ||
created_at: { $lt: Date.now() - ms(config.emailRetention) } | ||
}, | ||
{ writeConcern: { w: 0, j: false } } | ||
); | ||
} catch (err) { | ||
await logger.error(err); | ||
// send an email to admins of the error | ||
await emailHelper({ | ||
template: 'alert', | ||
message: { | ||
to: config.email.message.from, | ||
subject: 'Delete Emails Issue' | ||
}, | ||
locals: { | ||
message: `<pre><code>${JSON.stringify( | ||
parseErr(err), | ||
null, | ||
2 | ||
)}</code></pre>` | ||
} | ||
}); | ||
} | ||
|
||
if (parentPort) parentPort.postMessage('done'); | ||
else process.exit(0); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters