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

#4076 - Queue Monitoring - Schedulers Refactor (SFAS Integration) #4097

Merged
merged 8 commits into from
Dec 16, 2024
Merged
Prev Previous commit
Next Next commit
Refactor sims-to-sfas-integration
andrewsignori-aot committed Dec 13, 2024
commit 027960db9378f6abe137611ebe3a85a7bde61766
Original file line number Diff line number Diff line change
@@ -145,9 +145,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
const expectedFileName = buildExpectedFileName(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
@@ -212,9 +210,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
MockDate.set(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
@@ -272,9 +268,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
const expectedFileName = buildExpectedFileName(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
@@ -395,9 +389,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
const expectedFileName = buildExpectedFileName(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
@@ -476,9 +468,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
const expectedFileName = buildExpectedFileName(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
@@ -567,9 +557,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
const expectedFileName = buildExpectedFileName(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
@@ -649,9 +637,7 @@ describe(describeProcessorRootTest(QueueNames.SIMSToSFASIntegration), () => {
const expectedFileName = buildExpectedFileName(mockedCurrentDate);

// Act
const processingResult = await processor.generateSFASBridgeFile(
mockedJob.job,
);
const processingResult = await processor.processQueue(mockedJob.job);

// Assert
// Assert process result.
Original file line number Diff line number Diff line change
@@ -7,10 +7,6 @@ import {
LoggerService,
ProcessSummary,
} from "@sims/utilities/logger";
import {
getSuccessMessageWithAttentionCheck,
logProcessSummaryToJobLogger,
} from "../../../utilities";
import { QueueNames } from "@sims/utilities";
import { SIMSToSFASProcessingService } from "@sims/integrations/sfas-integration";
import { SIMSToSFASService } from "@sims/integrations/services/sfas";
@@ -28,82 +24,57 @@ export class SIMSToSFASIntegrationScheduler extends BaseScheduler<void> {
super(schedulerQueue, queueService);
}

/**
* To be removed once the method {@link process} is implemented.
* This method "hides" the {@link Process} decorator from the base class.
*/
async processQueue(): Promise<string | string[]> {
throw new Error("Method not implemented.");
}

/**
* When implemented in a derived class, process the queue job.
* To be implemented.
*/
protected async process(): Promise<string | string[]> {
throw new Error("Method not implemented.");
}

/**
* Generate data file consisting of all student, application and restriction updates in SIMS since the previous file generation
* until the start of the current job and send the data file to SFAS.
* @param job job.
* @returns process summary.
* @param _job process job.
* @param processSummary process summary for logging.
*/
@Process()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The decorator is expected to be removed right?

async generateSFASBridgeFile(job: Job<void>): Promise<string[]> {
const processSummary = new ProcessSummary();

try {
processSummary.info(
`Processing SIMS to SFAS integration job. Job id: ${job.id} and Job name: ${job.name}.`,
);
// Set the bridge data extracted date as current date-time
// before staring to process the bridge data.
const bridgeDataExtractedDate = new Date();
const latestBridgeFileReferenceDate =
await this.simsToSFASService.getLatestBridgeFileLogDate();
// If the bridge is being executed for the first time, set the modified since date to
// a safe initial date.
const modifiedSince =
latestBridgeFileReferenceDate ?? SIMS_TO_SFAS_BRIDGE_FILE_INITIAL_DATE;
processSummary.info(
`Processing data since ${modifiedSince} until ${bridgeDataExtractedDate}.`,
);
const integrationProcessSummary = new ProcessSummary();
processSummary.children(integrationProcessSummary);
const {
studentRecordsSent,
applicationRecordsSent,
restrictionRecordsSent,
uploadedFileName,
} = await this.simsToSFASIntegrationProcessingService.processSIMSUpdates(
integrationProcessSummary,
modifiedSince,
bridgeDataExtractedDate,
);
processSummary.info("Processing SIMS to SFAS integration job completed.");
return getSuccessMessageWithAttentionCheck(
[
"Process finalized with success.",
`Student records sent: ${studentRecordsSent}.`,
`Application records sent: ${applicationRecordsSent}.`,
`Restriction records sent: ${restrictionRecordsSent}.`,
`Uploaded file name: ${uploadedFileName}.`,
],
processSummary,
);
} catch (error: unknown) {
const errorMessage =
"Unexpected error while executing the SIMS to SFAS integration job.";
processSummary.error(errorMessage, error);
throw new Error(errorMessage, { cause: error });
} finally {
this.logger.logProcessSummary(processSummary);
await logProcessSummaryToJobLogger(processSummary, job);
}
protected async process(
_job: Job<void>,
processSummary: ProcessSummary,
): Promise<string[]> {
// Set the bridge data extracted date as current date-time
// before staring to process the bridge data.
const bridgeDataExtractedDate = new Date();
const latestBridgeFileReferenceDate =
await this.simsToSFASService.getLatestBridgeFileLogDate();
// If the bridge is being executed for the first time, set the modified since date to
// a safe initial date.
const modifiedSince =
latestBridgeFileReferenceDate ?? SIMS_TO_SFAS_BRIDGE_FILE_INITIAL_DATE;
processSummary.info(
`Processing data since ${modifiedSince} until ${bridgeDataExtractedDate}.`,
);
const integrationProcessSummary = new ProcessSummary();
processSummary.children(integrationProcessSummary);
const {
studentRecordsSent,
applicationRecordsSent,
restrictionRecordsSent,
uploadedFileName,
} = await this.simsToSFASIntegrationProcessingService.processSIMSUpdates(
integrationProcessSummary,
modifiedSince,
bridgeDataExtractedDate,
);
return [
"Process finalized with success.",
`Student records sent: ${studentRecordsSent}.`,
`Application records sent: ${applicationRecordsSent}.`,
`Restriction records sent: ${restrictionRecordsSent}.`,
`Uploaded file name: ${uploadedFileName}.`,
];
}

/**
* Logger for SFAS integration scheduler.
* Setting the logger here allows the correct context to be set
* during the property injection.
* Even if the logger is not used, it is required to be set, to
* allow the base classes to write logs using the correct context.
*/
@InjectLogger()
logger: LoggerService;
}