Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,13 @@ export const resendNotificationById = async (req: Request, res: Response) => {
if (!notification) {
return res.status(404).send('Notification not found.');
}
// Cancel the original notification first if it's still Pending!
if (notification.Status === NotificationStatus.Pending) {
const resultantNotification = await notificationServices.cancelNotificationById(
notification.Id,
user,
);
if (resultantNotification.Status !== NotificationStatus.Cancelled) {
return res
.status(500)
.send(`Failed to cancel original notification: ${notification.Id}. Resend aborted.`);
}
}
// NOTE: Originally, we would cancel the original notification first if it's still Pending.
// But now that we don't leave Pending notifications in CHES's queue,
// resending a Pending notification is equal to doing nothing on our part.
// sendNotification should handle that case.

const resultantNotification = await notificationServices.sendNotification(notification, user);
const updatedNotification = await notificationServices.updateNotificationStatus(
const updatedNotification = await notificationServices.syncNotificationWithChes(
resultantNotification.Id,
user,
);
Expand Down
26 changes: 22 additions & 4 deletions express-api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { AppDataSource } from '@/appDataSource';
import { Application } from 'express';
import { IncomingMessage, Server, ServerResponse } from 'http';
import cron from 'node-cron';
import failedEmailCheck from '@/utilities/failedEmailCheck';
import {
failedNotificationCheck,
sendQueuedNotifications,
syncNotificationStatuses,
} from '@/utilities/notificationChecks';
import clearIdleConnections from '@/utilities/clearIdleConnections';

const { API_PORT } = constants;
Expand All @@ -21,11 +25,25 @@ const startApp = (app: Application) => {
if (err) logger.error(err);
logger.info(`Server started on port ${API_PORT}.`);

// 0 * * * * == Triggers every hour
cron.schedule('0 * * * *', async () => {
logger.info('Send queued notifications: Starting');
await sendQueuedNotifications();
logger.info('Send queued notifications: Completed');
});

// */15 * * * * == Triggers every 15 mins
cron.schedule('*/15 * * * *', async () => {
logger.info('Sync notification statuses: Starting');
await syncNotificationStatuses();
logger.info('Sync notification statuses: Completed');
});

// 0 2 * * * == Triggers every 2:00AM
cron.schedule('0 2 * * *', async () => {
logger.info('Failed email check: Starting');
await failedEmailCheck();
logger.info('Failed email check: Completed');
logger.info('Failed-notification check: Starting');
await failedNotificationCheck();
logger.info('Failed-notification check: Completed');
});

// 0 1 * * 6 == Triggers 1:00AM on Saturday
Expand Down
2 changes: 1 addition & 1 deletion express-api/src/services/agencies/agencyServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const updateAgencyById = async (agencyIn: Agency, user: User) => {
// Attempt to resend notifications with new info
const resendResults = await Promise.allSettled(
affectedNotifications.map((notification) =>
notificationServices.resendNotificationWithNewProperties(
notificationServices.requeueNotificationWithNewProperties(
notification,
user,
{
Expand Down
Loading
Loading