import dotenv from 'dotenv' // note: dotenv does not overwrite values previously set dotenv.config({ path: `${process.cwd()}/prisma/.env` }) dotenv.config({ path: `${process.cwd()}/.env` }) import { logger } from '../utils/logger' // import '../tracer' import Queue from 'bull' // import verifyOrderWithSubscription from './order/subscriptions' import verifyOrdersStatusBasedOnCurrentDateTime from './order/status' import verifyEventReminder from './event/reminder' import verifyThatAllUserWithCurrentProjectAlsoHaveTheProjectInProjects from './user/addResidentCurrentProjectToListOfProjects' import sendNotification from './notification/send' import sendPost from './post/sendPost' import handleZoomWebhook from './zoom/handleZoomWebhook' import syncCondoManagerJob from './condomanager/sync' import createServiceProjectsForService from './service/createServiceProjectsForService' import { HANDLE_ZOOM_WEBHOOK_QUEUE_NAME, HANDLE_SYNC_CONDO_MANAGER_QUEUE_NAME, SEND_POST_QUEUE_NAME, SEND_NOTIFICATION_QUEUE_NAME, CREATE_SERVICE_PROJECT_FOR_SERVICE_QUEUE_NAME, } from '../queues' function defaultJobOptions(pattern) { return { removeOnComplete: true, attempts: 3, repeat: { cron: pattern, tz: 'America/New_York', }, } } try { logger.info(`Connecting to redis redis://${process.env.REDIS_HOST}`) const queue = new Queue('queue', `redis://${process.env.REDIS_HOST}`) queue.on('error', function (error) { logger.info(error) }) queue.on('waiting', function (jobId) { // A Job is waiting to be processed as soon as a worker is idling. logger.info(`Job id ${jobId} is waiting`) }) queue.on('active', function (job) { // A job has started. You can use `jobPromise.cancel()`` to abort it. logger.info(`"${job.name} - ${job.id}" is active`) }) queue.on('stalled', function (job) { // A job has been marked as stalled. This is useful for debugging job // workers that crash or pause the event loop. logger.info(`"${job.name} - ${job.id}" is stalled`) }) queue.on('progress', function (job) { // A job's progress was updated! logger.info(`"${job.name} - ${job.id}" is in progress`) }) queue.on('completed', function (job) { // A job successfully completed with a `result`. logger.info(`"${job.name} - ${job.id}" is completed`) }) queue.on('failed', function (job) { // A job failed with reason `err`! logger.info(`"${job.name} - ${job.id}" has failed`) }) queue.on('paused', function (job) { // The queue has been paused. logger.info(`"${job.name} - ${job.id}" is paused`) }) queue.on('resumed', function (job) { // The queue has been resumed. logger.info(`"${job.name} - ${job.id}" is resumed`) }) queue.on('cleaned', function () { // Old jobs have been cleaned from the queue. `jobs` is an array of cleaned // jobs, and `type` is the type of jobs cleaned. logger.info('Jobs cleaned') }) queue.on('drained', function () { // Emitted every time the queue has processed all the waiting jobs (even if there can be some delayed jobs not yet processed) logger.info('Finish processing all waiting jobs') }) queue.on('removed', function (job) { // A job successfully removed. logger.info(`"${job.name} - ${job.id}" is removed`) }) queue .process(CREATE_SERVICE_PROJECT_FOR_SERVICE_QUEUE_NAME, 1, createServiceProjectsForService) .catch(logger.error) queue.process(SEND_NOTIFICATION_QUEUE_NAME, 1, sendNotification).catch(logger.error) queue.process(SEND_POST_QUEUE_NAME, 1, sendPost).catch(logger.error) queue.process(HANDLE_ZOOM_WEBHOOK_QUEUE_NAME, 1, handleZoomWebhook).catch(logger.error) queue.process(HANDLE_SYNC_CONDO_MANAGER_QUEUE_NAME, 1, syncCondoManagerJob).catch(logger.error) // queue.process('Verify order with subscription', verifyOrderWithSubscription).catch(logger.error) queue.process('Verify event reminder', verifyEventReminder).catch(logger.error) queue.process('Verify order status', verifyOrdersStatusBasedOnCurrentDateTime).catch(logger.error) queue .process( 'Verify user projects', verifyThatAllUserWithCurrentProjectAlsoHaveTheProjectInProjects ) .catch(logger.error) queue.add('Verify event reminder', null, defaultJobOptions('0 * * * *')).catch(logger.error) queue.add('Verify order status', null, defaultJobOptions('10 1/5 * * *')).catch(logger.error) // Not using those jobs below for now... // queue.add('Sync condo managers', defaultJobOptions('0 0 * * *') }) // queue.add('Second invite', defaultJobOptions('0 * * * *')) // queue.add('Verify order with subscription', null, defaultJobOptions('15 1/5 * * *')) // queue.add('Verify user projects', null, defaultJobOptions('20 1/5 * * *')) // queue.add('Verify SendBird channel data', null, defaultJobOptions('25 1/5 * * *')) // queue.add(`Sync Condo Manager's data`, null, defaultJobOptions('0 23 * * *')) } catch (err) { logger.error(`error trying to connect to redis ${process.env.REDIS_HOST}: ${err.message}`) }