Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4079 - Queue Monitoring - Schedulers Refactor - (MSFAA) #4141

Merged
merged 4 commits into from
Dec 20, 2024
Merged
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 @@ -26,11 +26,16 @@ export abstract class BaseQueue<T> {
async processQueue(job: Job<T>): Promise<string | string[]> {
const processSummary = new ProcessSummary();
try {
processSummary.info(
`Processing queue ${job.queue.name}, job ID ${job.id}.`,
);
// Log the start of the process for the summary and logger.
const startLogMessage = `Processing queue ${job.queue.name}, job ID ${job.id}.`;
processSummary.info(startLogMessage);
this.logger.log(startLogMessage);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// Execute the process.
const result = await this.process(job, processSummary);
processSummary.info(`${job.queue.name}, job ID ${job.id}, executed.`);
// Log the end of the process for the summary and logger.
const endLogMessage = `${job.queue.name}, job ID ${job.id}, finished.`;
processSummary.info(endLogMessage);
this.logger.log(endLogMessage);
const logsSum = processSummary.getLogLevelSum();
if (logsSum.error) {
throw new CustomNamedError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DeepMocked, createMock } from "@golevelup/ts-jest";
import { DeepMocked } from "@golevelup/ts-jest";
import { INestApplication } from "@nestjs/common";
import { QueueNames, getISODateOnlyString } from "@sims/utilities";
import {
createTestingAppModule,
describeProcessorRootTest,
mockBullJob,
} from "../../../../../../test/helpers";
import { FullTimeMSFAAProcessResponseIntegrationScheduler } from "../msfaa-full-time-process-response-integration.scheduler";
import {
Expand All @@ -27,7 +28,6 @@ import {
NotificationMessageType,
} from "@sims/sims-db";
import * as Client from "ssh2-sftp-client";
import { Job } from "bull";
import * as path from "path";
import { FULL_TIME_SAMPLE_MSFAA_NUMBER } from "./msfaa-process-integration.scheduler.models";
import { IsNull } from "typeorm";
Expand Down Expand Up @@ -140,26 +140,29 @@ describe(
},
);
// Queued job.
const job = createMock<Job<void>>();
const mockedJob = mockBullJob<void>();
mockDownloadFiles(sftpClientMock, [
MSFAA_FULL_TIME_RECEIVE_FILE_WITH_REACTIVATION_RECORD,
]);

// Act
// Now reactivate the cancelled MSFAA.
const processResult = await processor.processMSFAA(job);
const result = await processor.processQueue(mockedJob.job);

// Assert
expect(processResult).toStrictEqual([
{
processSummary: [
`Processing file ${MSFAA_FULL_TIME_RECEIVE_FILE_WITH_REACTIVATION_RECORD}.`,
"File contains:",
"Confirmed MSFAA records (type R): 1.",
"Cancelled MSFAA records (type C): 0.",
"Record from line 2, updated as confirmed.",
],
errorsSummary: [],
},
expect(result).toStrictEqual([
"MSFAA full-time response files processed.",
]);
expect(
mockedJob.containLogMessages([
`Processing file ${MSFAA_FULL_TIME_RECEIVE_FILE_WITH_REACTIVATION_RECORD}.`,
"File contains:",
"Confirmed MSFAA records (type R): 1.",
"Cancelled MSFAA records (type C): 0.",
"Record from line 2, updated as confirmed.",
]),
).toBe(true);

// Assert that the file was archived from SFTP.
expect(sftpClientMock.rename).toHaveBeenCalled();
// Find the updated MSFAA records previously created.
Expand Down Expand Up @@ -259,12 +262,27 @@ describe(
),
);
// Queued job.
const job = createMock<Job<void>>();
const mockedJob = mockBullJob<void>();
mockDownloadFiles(sftpClientMock, [
MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD,
]);
// Act
const processResult = await processor.processMSFAA(job);
const result = await processor.processQueue(mockedJob.job);

// Assert
expect(result).toStrictEqual([
"MSFAA full-time response files processed.",
]);
expect(
mockedJob.containLogMessages([
`Processing file ${MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD}.`,
"File contains:",
"Confirmed MSFAA records (type R): 0.",
"Cancelled MSFAA records (type C): 1.",
"Record from line 2, updated as cancelled.",
]),
).toBe(true);
// Assert database changes.
const cancelledMSFAARecord = await db.msfaaNumber.findOne({
select: {
cancelledDate: true,
Expand Down Expand Up @@ -292,19 +310,6 @@ describe(
},
},
});
// Assert
expect(processResult).toStrictEqual([
{
processSummary: [
`Processing file ${MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD}.`,
"File contains:",
"Confirmed MSFAA records (type R): 0.",
"Cancelled MSFAA records (type C): 1.",
"Record from line 2, updated as cancelled.",
],
errorsSummary: [],
},
]);
expect(cancelledMSFAARecord.cancelledDate).toBe("2021-11-24");
expect(cancelledMSFAARecord.newIssuingProvince).toBe("ON");
expect(notification.dateSent).toBe(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Job } from "bull";
import { DeepMocked, createMock } from "@golevelup/ts-jest";
import { DeepMocked } from "@golevelup/ts-jest";
import { INestApplication } from "@nestjs/common";
import { QueueNames, getISODateOnlyString } from "@sims/utilities";
import {
createTestingAppModule,
describeProcessorRootTest,
mockBullJob,
} from "../../../../../../test/helpers";
import { PartTimeMSFAAProcessIntegrationScheduler } from "../msfaa-part-time-process-integration.scheduler";
import { E2EDataSources, createE2EDataSources } from "@sims/test-utils";
Expand Down Expand Up @@ -70,13 +70,13 @@ describe(
msfaaInputData,
);
// Queued job.
const job = createMock<Job<void>>();
const mockedJob = mockBullJob<void>();
// Spy on the MSFAA content creation to intercept the process date and time used.
const createMSFAARequestContentMock =
createMSFAARequestContentSpyOnMock(app);

// Act
const msfaaRequestResults = await processor.processMSFAA(job);
const result = await processor.processQueue(mockedJob.job);

// Assert
expect(createMSFAARequestContentMock).toHaveBeenCalledTimes(1);
Expand All @@ -87,14 +87,10 @@ describe(
`MSFT-Request\\DPBC.EDU.MSFA.SENT.PT.${processDateFormatted}.010`,
);
// Assert process result.
expect(msfaaRequestResults).toStrictEqual([
{
generatedFile: uploadedFile.remoteFilePath,
uploadedRecords: msfaaInputData.length,
offeringIntensity: OfferingIntensity.partTime,
},
expect(result).toStrictEqual([
`Generated file: ${uploadedFile.remoteFilePath}`,
`Uploaded records: ${msfaaInputData.length}`,
]);

// Assert file output.
expect(uploadedFile.fileLines?.length).toBe(msfaaInputData.length + 2);
const [
Expand Down
Loading
Loading