Skip to content

Commit

Permalink
HARMONY-1996: Remove unneeded dB constraint and fix casing on model
Browse files Browse the repository at this point in the history
sub_status field to be consistent
  • Loading branch information
indiejames committed Jan 24, 2025
1 parent 57ad87c commit 48b513b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 30 deletions.
11 changes: 3 additions & 8 deletions db/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,13 @@ export async function processWorkItem(
): Promise<void> {
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 {
Expand Down Expand Up @@ -701,7 +701,7 @@ export async function processWorkItem(
tx,
workItemID,
status,
subStatus,
sub_status,
duration,
totalItemsSize,
outputItemSizes);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion services/harmony/app/models/work-item-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion services/harmony/app/models/work-item-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions services/harmony/app/models/work-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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[],
Expand All @@ -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;
}
Expand All @@ -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<void> {
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 } };
Expand Down
4 changes: 2 additions & 2 deletions services/harmony/test/work-items/work-backends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 () {
Expand Down

0 comments on commit 48b513b

Please sign in to comment.