diff --git a/db/db.sql b/db/db.sql index 1c19e70b5..1f07d22ef 100644 --- a/db/db.sql +++ b/db/db.sql @@ -47,12 +47,7 @@ CREATE TABLE `job_errors` ( 'warning' ) ) not null default 'error', - `category` varchar(255) check ( - `category` in ( - 'generic', - 'no-data' - ) - ) not null default 'generic', + `category` varchar(255) not null default 'generic', `createdAt` datetime not null, `updatedAt` datetime not null, FOREIGN KEY(jobID) REFERENCES jobs(jobID) @@ -93,7 +88,7 @@ CREATE TABLE `work_items` ( `scrollID` varchar(4096), `serviceID` varchar(255) not null, `status` varchar(255) check (`status` in ('ready', 'queued', 'running', 'successful', 'failed', 'canceled', 'warning')) not null, - `subStatus` varchar(255) check (`subStatus` in ('no-data')), + `sub_status` varchar(255) check (`sub_status` in ('no-data')), `stacCatalogLocation` varchar(255), `totalItemsSize` double precision not null default 0, `outputItemSizesJson` text, @@ -201,7 +196,7 @@ CREATE INDEX job_errors_category_idx ON job_errors(category); CREATE INDEX work_items_jobID_idx ON work_items(jobID); CREATE INDEX work_items_serviceID_idx ON work_items(serviceID); CREATE INDEX work_items_status_idx ON work_items(status); -CREATE INDEX work_items_subStatus_idx ON work_items(subStatus); +CREATE INDEX work_items_sub_status_idx ON work_items(sub_status); CREATE INDEX workflow_steps_jobID_idx ON workflow_steps(jobID); CREATE INDEX workflow_steps_jobID_StepIndex_idx ON workflow_steps(jobID, stepIndex); CREATE INDEX workflow_steps_serviceID_idx ON workflow_steps(serviceID); diff --git a/db/migrations/20250124155544_add_level_and_category_to_job_errors.js b/db/migrations/20250124155544_add_level_and_category_to_job_errors.js index 7ffcbc981..df0b7e376 100644 --- a/db/migrations/20250124155544_add_level_and_category_to_job_errors.js +++ b/db/migrations/20250124155544_add_level_and_category_to_job_errors.js @@ -8,9 +8,7 @@ exports.up = function (knex, Promise) { ADD COLUMN "level" VARCHAR(255) DEFAULT 'error' NOT NULL, ADD CONSTRAINT "job_errors_level_check" CHECK (level IN ('error', 'warning')), - ADD COLUMN "category" VARCHAR(255) DEFAULT 'generic' NOT NULL, - ADD CONSTRAINT "job_errors_category_check" - CHECK (category IN ('generic', 'no-data')); + ADD COLUMN "category" VARCHAR(255) DEFAULT 'generic' NOT NULL; CREATE INDEX job_errors_level ON job_errors (level); CREATE INDEX job_errors_category ON job_errors (category) diff --git a/services/harmony/app/backends/workflow-orchestration/work-item-updates.ts b/services/harmony/app/backends/workflow-orchestration/work-item-updates.ts index 423fbf455..67e4d2771 100644 --- a/services/harmony/app/backends/workflow-orchestration/work-item-updates.ts +++ b/services/harmony/app/backends/workflow-orchestration/work-item-updates.ts @@ -609,13 +609,13 @@ export async function processWorkItem( ): Promise { const { jobID } = job; const { status, errorMessage, catalogItems, outputItemSizes } = preprocessResult; - const { workItemID, hits, results, scrollID, subStatus } = update; + const { workItemID, hits, results, scrollID, sub_status } = update; const startTime = new Date().getTime(); let durationMs; let jobSaveStartTime; let didCreateWorkItem = false; if (status === WorkItemStatus.SUCCESSFUL || status === WorkItemStatus.WARNING) { - logger.info(`Updating work item ${workItemID} to ${status} | ${subStatus}`); + logger.info(`Updating work item ${workItemID} to ${status} | ${sub_status}`); } try { @@ -701,7 +701,7 @@ export async function processWorkItem( tx, workItemID, status, - subStatus, + sub_status, duration, totalItemsSize, outputItemSizes); @@ -713,7 +713,7 @@ export async function processWorkItem( logger.info(`Updated work item. Duration (ms) was: ${duration}`); workItem.status = status; - workItem.subStatus = subStatus; + workItem.sub_status = sub_status; let allWorkItemsForStepComplete = false; diff --git a/services/harmony/app/backends/workflow-orchestration/workflow-orchestration.ts b/services/harmony/app/backends/workflow-orchestration/workflow-orchestration.ts index a8e50161f..2c4e4e6c8 100644 --- a/services/harmony/app/backends/workflow-orchestration/workflow-orchestration.ts +++ b/services/harmony/app/backends/workflow-orchestration/workflow-orchestration.ts @@ -96,7 +96,7 @@ export async function updateWorkItem(req: HarmonyRequest, res: Response): Promis const { id } = req.params; const { status, - subStatus, + sub_status, hits, results, scrollID, @@ -117,7 +117,7 @@ export async function updateWorkItem(req: HarmonyRequest, res: Response): Promis const update = { workItemID: parseInt(id), status, - subStatus, + sub_status, hits, results, scrollID, diff --git a/services/harmony/app/models/work-item-interface.ts b/services/harmony/app/models/work-item-interface.ts index f91e28089..e14023bd5 100644 --- a/services/harmony/app/models/work-item-interface.ts +++ b/services/harmony/app/models/work-item-interface.ts @@ -44,7 +44,7 @@ export interface WorkItemRecord { status?: WorkItemStatus; // The sub-status of the operation - see WorkItemSubStatus - subStatus?: WorkItemSubStatus; + sub_status?: WorkItemSubStatus; // error message if status === FAILED errorMessage?: string; diff --git a/services/harmony/app/models/work-item-update.ts b/services/harmony/app/models/work-item-update.ts index a3e256736..938589535 100644 --- a/services/harmony/app/models/work-item-update.ts +++ b/services/harmony/app/models/work-item-update.ts @@ -15,7 +15,7 @@ export default interface WorkItemUpdate { status?: WorkItemStatus; // The sub-status of the operation - see WorkItemSubStatus - subStatus?: WorkItemSubStatus; + sub_status?: WorkItemSubStatus; // The ID of the scroll session (only used for the query cmr service) scrollID?: string; diff --git a/services/harmony/app/models/work-item.ts b/services/harmony/app/models/work-item.ts index ea25b95f3..d1bf10882 100644 --- a/services/harmony/app/models/work-item.ts +++ b/services/harmony/app/models/work-item.ts @@ -52,7 +52,7 @@ export default class WorkItem extends Record implements WorkItemRecord { status?: WorkItemStatus; // The sub-status of the operation - see WorkItemSubStatus - subStatus?: WorkItemSubStatus; + sub_status?: WorkItemSubStatus; // error message if status === FAILED errorMessage?: string; @@ -300,7 +300,7 @@ export async function getWorkItemStatus( * @param tx - the transaction to use for querying * @param id - the id of the WorkItem * @param status - the status to set for the WorkItem - * @param subStatus - the sub-status to set for the WorkItem + * @param sub_status - the sub-status to set for the WorkItem * @param duration - how long the work item took to process * @param totalItemsSize - the combined sizes of all the input granules for this work item * @param outputItemSizes - the separate size of each granule in the output for this work item @@ -309,7 +309,7 @@ export async function updateWorkItemStatus( tx: Transaction, id: number, status: WorkItemStatus, - subStatus: WorkItemSubStatus, + sub_status: WorkItemSubStatus, duration: number, totalItemsSize: number, outputItemSizes: number[], @@ -318,11 +318,11 @@ export async function updateWorkItemStatus( const outputItemSizesJson = JSON.stringify(outputItemSizes); try { await tx(WorkItem.table) - .update({ status, subStatus, duration, totalItemsSize, outputItemSizesJson: outputItemSizesJson, updatedAt: new Date() }) + .update({ status, sub_status, duration, totalItemsSize, outputItemSizesJson: outputItemSizesJson, updatedAt: new Date() }) .where({ id }); - logger.debug(`Status for work item ${id} set to ${status} | ${subStatus}`); + logger.debug(`Status for work item ${id} set to ${status} | ${sub_status}`); } catch (e) { - logger.error(`Failed to update work item ${id} status to ${status} | ${subStatus}`); + logger.error(`Failed to update work item ${id} status to ${status} | ${sub_status}`); logger.error(e); throw e; } @@ -333,16 +333,16 @@ export async function updateWorkItemStatus( * @param tx - the transaction to use for querying * @param ids - the ids of the WorkItems * @param status - the status to set for the WorkItems - * @param subStatus - the sub-status to set for the WorkItems + * @param sub_status - the sub-status to set for the WorkItems */ export async function updateWorkItemStatuses( tx: Transaction, ids: number[], status: WorkItemStatus, - subStatus?: WorkItemSubStatus, + sub_status?: WorkItemSubStatus, ): Promise { const now = new Date(); - let update = { status, subStatus, updatedAt: now }; + let update = { status, sub_status, updatedAt: now }; // if we are setting the status to running, also set the startedAt time if (status === WorkItemStatus.RUNNING) { update = { ...update, ...{ startedAt: now } }; diff --git a/services/harmony/test/work-items/work-backends.ts b/services/harmony/test/work-items/work-backends.ts index beb0e08ca..0f5d770f0 100644 --- a/services/harmony/test/work-items/work-backends.ts +++ b/services/harmony/test/work-items/work-backends.ts @@ -491,7 +491,7 @@ describe('Work Backends', function () { ...workItemRecord, ...{ status: WorkItemStatus.WARNING, - subStatus: WorkItemSubStatus.NO_DATA, + sub_status: WorkItemSubStatus.NO_DATA, results: [getStacLocation({ id: workItemRecord.id, jobID: workItemRecord.jobID }, 'catalog.json')], outputItemSizes: [], duration: 0, @@ -505,7 +505,7 @@ describe('Work Backends', function () { it('sets the work item status to warning with no-data', async function () { const updatedWorkItem = await getWorkItemById(db, this.workItem.id); expect(updatedWorkItem.status).to.equal(WorkItemStatus.WARNING); - expect(updatedWorkItem.subStatus).to.equal(WorkItemSubStatus.NO_DATA); + expect(updatedWorkItem.sub_status).to.equal(WorkItemSubStatus.NO_DATA); }); describe('and the worker computed duration is less than the harmony computed duration', async function () {