From ecb4e35f4e6c7304cb274593c13cb47fd5078b75 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 30 Jan 2018 13:27:07 +0100 Subject: Add ability to reset our password --- server/lib/job-queue/handlers/email.ts | 22 ++++++++++++++++++++++ server/lib/job-queue/job-queue.ts | 9 +++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 server/lib/job-queue/handlers/email.ts (limited to 'server/lib/job-queue') diff --git a/server/lib/job-queue/handlers/email.ts b/server/lib/job-queue/handlers/email.ts new file mode 100644 index 000000000..9d7686116 --- /dev/null +++ b/server/lib/job-queue/handlers/email.ts @@ -0,0 +1,22 @@ +import * as kue from 'kue' +import { logger } from '../../../helpers/logger' +import { Emailer } from '../../emailer' + +export type EmailPayload = { + to: string[] + subject: string + text: string +} + +async function processEmail (job: kue.Job) { + const payload = job.data as EmailPayload + logger.info('Processing email in job %d.', job.id) + + return Emailer.Instance.sendMail(payload.to, payload.subject, payload.text) +} + +// --------------------------------------------------------------------------- + +export { + processEmail +} diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 7a2b6c78d..3f176f896 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts @@ -5,19 +5,22 @@ import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY } from '. import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' +import { EmailPayload, processEmail } from './handlers/email' import { processVideoFile, VideoFilePayload } from './handlers/video-file' type CreateJobArgument = { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } | { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } | - { type: 'video-file', payload: VideoFilePayload } + { type: 'video-file', payload: VideoFilePayload } | + { type: 'email', payload: EmailPayload } const handlers: { [ id in JobType ]: (job: kue.Job) => Promise} = { 'activitypub-http-broadcast': processActivityPubHttpBroadcast, 'activitypub-http-unicast': processActivityPubHttpUnicast, 'activitypub-http-fetcher': processActivityPubHttpFetcher, - 'video-file': processVideoFile + 'video-file': processVideoFile, + 'email': processEmail } class JobQueue { @@ -43,6 +46,8 @@ class JobQueue { } }) + this.jobQueue.setMaxListeners(15) + this.jobQueue.on('error', err => { logger.error('Error in job queue.', err) process.exit(-1) -- cgit v1.2.3