remove node-cron
This commit is contained in:
Родитель
cdefd34876
Коммит
512fdfbeb6
|
@ -6,7 +6,6 @@ const path = require('path')
|
|||
const { readdir } = require('fs/promises')
|
||||
const partialDir = path.join(path.dirname(require.main.filename), '/views/partials/email_partials')
|
||||
const { LocaleUtils } = require('./../locale-utils')
|
||||
const { initMinuteCron } = require('../cron')
|
||||
|
||||
let partialFilenames
|
||||
|
||||
|
@ -139,21 +138,7 @@ function sendTestEmail (data) {
|
|||
unsubscribeUrl
|
||||
}
|
||||
|
||||
async function sendEmail () {
|
||||
await EmailUtils.sendEmail(req.body.recipientEmail, subject, data.layout, context)
|
||||
}
|
||||
|
||||
if (req.body.delay === 'on') {
|
||||
initMinuteCron(sendEmail)
|
||||
|
||||
return res.send(`
|
||||
<h2>Email scheduled to send 1 minute from now!</h2>
|
||||
<p>${optoutNote}</p>
|
||||
<a href='/email-l10n/email-2022-mockup'>Go Back</a> | <a href='/user/logout'>Sign Out</a>
|
||||
`)
|
||||
}
|
||||
|
||||
await sendEmail()
|
||||
await EmailUtils.sendEmail(req.body.recipientEmail, subject, data.layout, context)
|
||||
|
||||
res.send(`
|
||||
<h2>Email sent!</h2>
|
||||
|
|
30
cron.js
30
cron.js
|
@ -1,30 +0,0 @@
|
|||
const cron = require('node-cron')
|
||||
|
||||
function initMonthlyCron (...jobs) {
|
||||
cron.schedule('* 16 1 * *', () => {
|
||||
// first of the month and 1600 UTC, 11am EST
|
||||
jobs.forEach(job => job())
|
||||
})
|
||||
}
|
||||
|
||||
// For testing node-cron
|
||||
function initMinuteCron (job) {
|
||||
console.log('running single cron job 1 minute from now')
|
||||
let killCron = false
|
||||
const cronMinute = cron.schedule('* * * * *', () => {
|
||||
console.log('running 1 minute cron job')
|
||||
killCron = true
|
||||
job()
|
||||
})
|
||||
|
||||
const interval = setInterval(() => {
|
||||
console.log('interval')
|
||||
if (killCron) {
|
||||
console.log('stopping cron')
|
||||
cronMinute.stop()
|
||||
clearInterval(interval)
|
||||
}
|
||||
}, 10000)
|
||||
}
|
||||
|
||||
module.exports = { initMonthlyCron, initMinuteCron }
|
|
@ -32,7 +32,6 @@
|
|||
"knex": "^2.2.0",
|
||||
"knex-paginate": "1.2.2",
|
||||
"mozlog": "3.0.2",
|
||||
"node-cron": "^3.0.2",
|
||||
"nodemailer": "^6.6.5",
|
||||
"nodemailer-express-handlebars": "5.0.0",
|
||||
"pg": "^8.7.1",
|
||||
|
@ -6892,25 +6891,6 @@
|
|||
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
|
||||
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
|
||||
},
|
||||
"node_modules/node-cron": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
|
||||
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
|
||||
"dependencies": {
|
||||
"uuid": "8.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/node-cron/node_modules/uuid": {
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/node-int64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
|
||||
|
@ -14920,21 +14900,6 @@
|
|||
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz",
|
||||
"integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw=="
|
||||
},
|
||||
"node-cron": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.2.tgz",
|
||||
"integrity": "sha512-iP8l0yGlNpE0e6q1o185yOApANRe47UPbLf4YxfbiNHt/RU5eBcGB/e0oudruheSf+LQeDMezqC5BVAb5wwRcQ==",
|
||||
"requires": {
|
||||
"uuid": "8.3.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"uuid": {
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"node-int64": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
"knex": "^2.2.0",
|
||||
"knex-paginate": "1.2.2",
|
||||
"mozlog": "3.0.2",
|
||||
"node-cron": "^3.0.2",
|
||||
"nodemailer": "^6.6.5",
|
||||
"nodemailer-express-handlebars": "5.0.0",
|
||||
"pg": "^8.7.1",
|
||||
|
@ -82,7 +81,6 @@
|
|||
"start": "npm run build & node server.js",
|
||||
"dev": "npm run build & nodemon server.js",
|
||||
"build": "node esbuild.js",
|
||||
"cron:monthly-email": "node -e \"require('./scripts/send-email-to-unresolved-breach-subscribers.js').sendUnresolvedBreachEmails()\"",
|
||||
"db:migrate": "knex migrate:latest --knexfile db/knexfile.js",
|
||||
"docker:build": "docker build -t blurts-server .",
|
||||
"docker:run": "docker run -p 6060:6060 blurts-server",
|
||||
|
|
|
@ -34,8 +34,6 @@ const EmailUtils = require('./email-utils')
|
|||
const HBSHelpers = require('./template-helpers/')
|
||||
const HIBP = require('./hibp')
|
||||
const IpLocationService = require('./ip-location-service')
|
||||
const { initMonthlyCron } = require('./cron')
|
||||
const { sendUnresolvedBreachEmails } = require('./scripts/send-email-to-unresolved-breach-subscribers')
|
||||
|
||||
const {
|
||||
addRequestToResponse, pickLanguage, logErrors, localizeErrorMessages,
|
||||
|
@ -259,8 +257,3 @@ EmailUtils.init().then(() => {
|
|||
}).catch(error => {
|
||||
log.error('try-initialize-email-error', { error })
|
||||
})
|
||||
|
||||
if (AppConstants.MONTHLY_CRON_ENABLED && AppConstants.MONTHLY_CRON_ENABLED !== 'false') {
|
||||
console.log('Starting monthly cron job.')
|
||||
initMonthlyCron(sendUnresolvedBreachEmails)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
<span style="font-size: 14px; display: flex; flex-flow: column; gap: 3px; align-items: end;">
|
||||
<input type="email" name="recipientEmail" placeholder="Recipient email"
|
||||
style="text-align: right; padding: 6px; border-radius: 6px; border: 2px solid #808080;">
|
||||
<label>1 minute delay <input type="checkbox" name="delay"></label>
|
||||
</span>
|
||||
<button type="submit"
|
||||
style="background-color: #666; color: white; border-radius: 6px; padding: 12px; border: 0; cursor: pointer">Send test
|
||||
|
|
Загрузка…
Ссылка в новой задаче