Skip to content

Commit

Permalink
comning all commits for #456 & #507 tasks to remove data
Browse files Browse the repository at this point in the history
  • Loading branch information
khgsa committed Oct 25, 2024
1 parent 9021a52 commit 8f29e1a
Show file tree
Hide file tree
Showing 20 changed files with 1,796 additions and 1,372 deletions.
2,111 changes: 1,071 additions & 1,040 deletions api/controllers/base.controller.js

Large diffs are not rendered by default.

94 changes: 42 additions & 52 deletions api/controllers/cron.controller.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
const ctrl = require('./base.controller'),
records = require('./records.controller'),
techCatImport = require('./tech-catalog-import.controller'),
touchpointImport= require('./touchpoint-import.controller'),
fs = require('fs'),
path = require('path'),
queryPath = '../queries/'
SHEET_ID = '1eSoyn7-2EZMqbohzTMNDcFmNBbkl-CzXtpwNXHNHD1A', // FOR PRODUCTION
RANGE = 'Master Junction with Business Systems!A2:B',
jobUser = 'GearCronJ';
cronJobDbUtilService = require('../cron-jobs/cron-job-db-util.service.js'),
JobLogger = require('../cron-jobs/job-logger.js'),
JobStatus = require('../enums/job-status.js');

const SHEET_ID = '1eSoyn7-2EZMqbohzTMNDcFmNBbkl-CzXtpwNXHNHD1A', // FOR PRODUCTION
RANGE = 'Master Junction with Business Systems!A2:B',
jobUser = 'GearCronJ';

// -------------------------------------------------------------------------------------------------
// CRON JOB: Google Sheets API - Update All Related Records
exports.runUpdateAllRelatedRecordsJob = async () => {

const jobType = "RELATED-RECORDS-JOB";
const jobName = `CRON JOB: Update All Related Records`;
let status = 'executed';

const jobLogger = new JobLogger();
let jobId;
try {
const pendingJobId = await cronJobDbUtilService.getAnyPendingJob(jobType);
if (pendingJobId) {
jobLogger.log(`Active Job '${pendingJobId}' is Running. Aborting the job now.`);
await cronJobDbUtilService.insertDbData({ jobType, startTime: ctrl.formatDateTime(new Date()), jobLogs: jobLogger.getLogs(), jobStatus: JobStatus.CANCELLED })
return;
}

let res = {};


jobId = await cronJobDbUtilService.insertDbData({ jobType, startTime: ctrl.formatDateTime(new Date()), jobLogs: '', jobStatus: JobStatus.PENDING });
console.log(jobId);

// log start of job
console.log(jobName + ' - ' + status);
jobLogger.log(jobName + ' - Execution start');

// log start of job to db
records.logEvent({ body : { message: jobName + ' - ' + status, user: jobUser, } }, res);

// run refreshAllSystems
ctrl.googleMain(res, 'refresh', SHEET_ID, RANGE, jobUser);

await ctrl.googleMain(res, 'refresh', SHEET_ID, RANGE, jobUser, null, jobLogger, jobId, postprocesJobExecution);
} catch (error) {
// log any errors
status = `error occurred while running: \n` + error;
console.log(jobName + ' - ' + status);
if (jobId) {
jobLogger.log(jobName + ' - ' + status);
jobLogger.log(error.stack);
await postprocesJobExecution(jobId, jobLogger, JobStatus.FAILURE);
} else {
jobLogger.log(error);
}
}
};

async function postprocesJobExecution(jobId, jobLogger, jobStatus) {
await cronJobDbUtilService.updateDbData({ jobStatus: jobStatus, endTime: ctrl.formatDateTime(new Date()), jobLogs: jobLogger.getLogs(), jobId: jobId })
}
// -------------------------------------------------------------------------------------------------
// CRON JOB: Tech Catalog Daily Import (runs daily at 5:00 AM)
exports.runTechCatalogImportJob = async () => {
Expand All @@ -54,15 +67,15 @@ exports.runTechCatalogImportJob = async () => {
ctrl.sendLogQuery(jobName + ' - ' + status, jobUser, jobName, res);

// run daily import
techCatImport.runDailyTechCatalogImport({ body : { refreshtoken : process.env.FLEXERA_REFRESH_TOKEN, requester : jobUser } }, res)
.then((response) => {
status = `finished successfully: \n` + response;
console.log(jobName + ' - ' + status);
})
.catch((error) => {
status = `error occurred while running: \n` + error;
console.log(jobName + ' - ' + status);
});
techCatImport.runDailyTechCatalogImport({ body: { refreshtoken: process.env.FLEXERA_REFRESH_TOKEN, requester: jobUser } }, res)
.then((response) => {
status = `finished successfully: \n` + response;
console.log(jobName + ' - ' + status);
})
.catch((error) => {
status = `error occurred while running: \n` + error;
console.log(jobName + ' - ' + status);
});

} catch (error) {
status = `error occurred starting: \n` + error;
Expand All @@ -72,30 +85,6 @@ exports.runTechCatalogImportJob = async () => {
};

// -------------------------------------------------------------------------------------------------
// CRON JOB: Touch point Daily Import (runs daily at 5:00 AM)
exports.runTouchpointImportJob = async () => {

const jobName = 'CRON JOB: Touchpoint Daily Import';
let status = 'executed';

console.log(jobName + ' - ' + status);

try {

let res = {};

// log execution of job
ctrl.sendLogQuery(jobName + ' - ' + status, jobUser, jobName, res);

// run daily import
touchpointImport.importWebsiteData();
} catch (error) {
status = `error occurred starting: \n` + error;
console.log(jobName + ' - ' + status);
}

};

/*
* Function to get FISMA info from ServiceNow API
* everyday at 20:00 Eastern Time
Expand Down Expand Up @@ -180,4 +169,5 @@ const putData = async data => {
console.log(jobName + ' - ' + status);
}
});*/
});*/

34 changes: 18 additions & 16 deletions api/controllers/records.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,29 @@ exports.updateSystems = (req, res) => {
};

// This function is called by the api to update all the records using a Google Sheet
exports.refreshAllSystems = (req, res) => {
ctrl.getApiToken (req, res)
.then((response) => {
exports.refreshAllSystems = async (req, res) => {
try {
const response = await ctrl.getApiToken(req, res);
console.log('*** API Security Testing - getApiToken response: ', response); //DEBUGGING

if (response === 1) {
console.log('*** API Security Testing - API Auth Validation: PASSED'); //DEBUGGING
var data = req.body;

console.log("refreshAllSystems")

// if (req.headers.authorization) {
// 'refresh' is used to set the callback_method = "refresh"
ctrl.googleMain(res, 'refresh', SHEET_ID, RANGE, req.headers.requester);
} else {
console.log('*** API Security Testing - API Auth Validation: FAILED'); //DEBUGGING
res.status(502).json({
message: "No authorization token present."

console.log("refreshAllSystems")
// 'refresh' is used to set the callback_method = "refresh"
await ctrl.googleMain(res, 'refresh', SHEET_ID, RANGE, req.headers.requester);
} else {
console.log('*** API Security Testing - API Auth Validation: FAILED'); //DEBUGGING
res.status(502).json({
message: "No authorization token present."
});
}
});
} catch (error) {
msgLog('*** API Security Testing - API Auth Validation: FAILED', null); //DEBUGGING
msgLog(error.stack, null); //DEBUGGING
res.status(502).json({
message: "No authorization token present."
});
}
};

// this function is called by the api to log an event to the database
Expand Down
175 changes: 0 additions & 175 deletions api/controllers/touchpoint-import.controller.js

This file was deleted.

Loading

0 comments on commit 8f29e1a

Please sign in to comment.