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

DRAFT [TTAHUB-2796] flag correction maintenance job #2200

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const MAINTENANCE_TYPE = {
VACUUM_TABLES: 'VACUUM TABLES',
REINDEX_TABLES: 'REINDEX TABLES',
DAILY_DB_MAINTENANCE: 'DAILY DB MAINTENANCE',
CORRECT_AR_FLAGS: 'CORRECT AR FLAGS',
CLEAR_MAINTENANCE_LOGS: 'CLEAR MAINTENANCE LOGS',
IMPORT_SCHEDULE: 'IMPORT_SCHEDULE',
IMPORT_DOWNLOAD: 'IMPORT_DOWNLOAD',
Expand Down
17 changes: 15 additions & 2 deletions src/lib/maintenance/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ const reindexTable = async (model, triggeredById = null) => tableMaintenanceComm
triggeredById,
);

/**
* Asynchronous function calling a stored procedure that corrects onApprovedAR and onAR flags.
* @returns {Promise} A promise that resolves when the stored procedure completes.
*/
const correctArFlags = async (triggeredById = null) => tableMaintenanceCommand(
'SELECT correct_ar_flags()', // SQL command to reindex a table
MAINTENANCE_CATEGORY.DB, // Maintenance category for database maintenance commands
MAINTENANCE_TYPE.CORRECT_AR_FLAGS, // Maintenance type for reindexing
triggeredById,
);

/**
* This function vacuums all tables in the database using Sequelize ORM.
* @param {number} offset - The starting index of the models to vacuum.
Expand Down Expand Up @@ -178,8 +189,10 @@ const dailyMaintenance = async (offset = 0, limit = numOfModels) => maintenanceC
await Promise.all([vacuumTablesPromise]);
// Reindex tables to optimize queries.
const reindexTablesPromise = reindexTables(offset, limit, triggeredById);
// Wait for both promises to resolve.
const results = await Promise.all([vacuumTablesPromise, reindexTablesPromise]);
// Correct onApprovedAR and onAR flags for Goals and Objectives.
const correctArFlagsPromise = correctArFlags(triggeredById);
// Wait for all promises to resolve.
const results = await Promise.all([vacuumTablesPromise, reindexTablesPromise, correctArFlagsPromise]);

// Return an object indicating whether all promises resolved successfully.
return { isSuccessful: results.every((r) => r === true) };
Expand Down
Loading