Skip to content

Commit

Permalink
feat: add suspended status code(MAPCO-5527) (#48)
Browse files Browse the repository at this point in the history
* feat: add suspended status code

* fix: EOF
  • Loading branch information
RonitKissis authored Dec 4, 2024
1 parent 30b0b57 commit 1cb313a
Show file tree
Hide file tree
Showing 22 changed files with 2,199 additions and 99 deletions.
1 change: 1 addition & 0 deletions openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ components:
- Failed
- Expired
- Aborted
- Suspended
example: Pending
jobResponse:
type: object
Expand Down
2,233 changes: 2,162 additions & 71 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@map-colonies/error-types": "^1.1.5",
"@map-colonies/express-access-log-middleware": "^2.0.1",
"@map-colonies/js-logger": "^1.0.1",
"@map-colonies/mc-priority-queue": "^8.2.1",
"@map-colonies/openapi-express-viewer": "^3.0.0",
"@map-colonies/read-pkg": "0.0.1",
"@map-colonies/telemetry": "^5.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/DAL/entity/job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Column, PrimaryColumn, Index, UpdateDateColumn, Generated, CreateDateColumn, OneToMany } from 'typeorm';
import { OperationStatus } from '../../common/dataModels/enums';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { TaskEntity } from './task';

@Entity('Job')
Expand Down
2 changes: 1 addition & 1 deletion src/DAL/entity/task.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Column, PrimaryColumn, UpdateDateColumn, Generated, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { OperationStatus } from '../../common/dataModels/enums';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { JobEntity } from './job';

@Entity('Task')
Expand Down
6 changes: 3 additions & 3 deletions src/DAL/migration/FullSchema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

SET search_path TO "JobManager", public; -- CHANGE SCHEMA NAME TO MATCH ENVIRONMENT
CREATE TYPE "operation_status_enum" AS ENUM
('Pending', 'In-Progress', 'Completed', 'Failed', 'Expired', 'Aborted');
('Pending', 'In-Progress', 'Completed', 'Failed', 'Expired', 'Aborted', 'Suspended');

CREATE TABLE "Job"
(
Expand Down Expand Up @@ -38,8 +38,8 @@ CREATE TABLE "Job"
"additionalIdentifiers" text COLLATE pg_catalog."default",
"domain" text COLLATE pg_catalog."default" NOT NULL DEFAULT ''::text,
CONSTRAINT "PK_job_id" PRIMARY KEY (id),
CONSTRAINT "UQ_uniqueness_on_active_tasks" EXCLUDE ("resourceId" with =, "version" with =, "type" with =, "additionalIdentifiers" with =) WHERE ((status = 'Pending' OR status = 'In-Progress') AND ("additionalIdentifiers" IS NOT NULL)),
CONSTRAINT "UQ_uniqueness_on_active_tasks_no_additional_identifier" EXCLUDE ("resourceId" with =, "version" with =, "type" with =) WHERE ((status = 'Pending' OR status = 'In-Progress') AND ("additionalIdentifiers" IS NULL))
CONSTRAINT "UQ_uniqueness_on_active_tasks" EXCLUDE ("resourceId" with =, "version" with =, "type" with =, "additionalIdentifiers" with =) WHERE ((status = 'Pending' OR status = 'In-Progress' OR status = 'Suspended') AND ("additionalIdentifiers" IS NOT NULL)),
CONSTRAINT "UQ_uniqueness_on_active_tasks_no_additional_identifier" EXCLUDE ("resourceId" with =, "version" with =, "type" with =) WHERE ((status = 'Pending' OR status = 'In-Progress' OR status = 'Suspended') AND ("additionalIdentifiers" IS NULL))
);

CREATE INDEX "jobCleanedIndex"
Expand Down
15 changes: 15 additions & 0 deletions src/DAL/migration/v.2.7.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SET search_path TO "JobManager", public; -- CHANGE SCHEMA NAME TO MATCH ENVIRONMENT

ALTER TYPE "JobManager"."operation_status_enum" ADD VALUE 'Suspended';

ALTER TABLE "Job"
DROP CONSTRAINT IF EXISTS "UQ_uniqueness_on_active_tasks";

ALTER TABLE "Job"
ADD CONSTRAINT "UQ_uniqueness_on_active_tasks" EXCLUDE ("resourceId" with =, "version" with =, "type" with =, "additionalIdentifiers" with =) WHERE ((status = 'Pending' OR status = 'In-Progress' OR status = 'Suspended') AND ("additionalIdentifiers" IS NOT NULL));

ALTER TABLE "Job"
DROP CONSTRAINT IF EXISTS "UQ_uniqueness_on_active_tasks_no_additional_identifier";

ALTER TABLE "Job"
ADD CONSTRAINT "UQ_uniqueness_on_active_tasks_no_additional_identifier" EXCLUDE ("resourceId" with =, "version" with =, "type" with =) WHERE ((status = 'Pending' OR status = 'In-Progress' OR status = 'Suspended') AND ("additionalIdentifiers" IS NULL));
4 changes: 2 additions & 2 deletions src/DAL/repositories/jobRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EntityRepository, FindManyOptions, LessThan, Brackets, Between, LessTha
import { container } from 'tsyringe';
import { Logger } from '@map-colonies/js-logger';
import { ConflictError, NotFoundError } from '@map-colonies/error-types';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { DBConstraintError } from '../../common/errors';
import { SERVICES } from '../../common/constants';
import { JobEntity } from '../entity/job';
Expand All @@ -17,7 +18,6 @@ import {
IFindJobsByCriteriaBody,
} from '../../common/dataModels/jobs';
import { JobModelConvertor } from '../convertors/jobModelConverter';
import { OperationStatus } from '../../common/dataModels/enums';
import { GeneralRepository } from './generalRepository';

export type JobParameters = Record<string, unknown>;
Expand Down Expand Up @@ -250,7 +250,7 @@ export class JobRepository extends GeneralRepository<JobEntity> {
FROM "Job" AS jb
INNER JOIN "Task" as tk ON tk."jobId" = jb.id
WHERE jb.id = $1 AND
(jb.status = '${OperationStatus.EXPIRED}' OR jb.status = '${OperationStatus.FAILED}' OR jb.status = '${OperationStatus.ABORTED}') AND
(jb.status = '${OperationStatus.EXPIRED}' OR jb.status = '${OperationStatus.FAILED}' OR jb.status = '${OperationStatus.ABORTED}' OR jb.status = '${OperationStatus.SUSPENDED}') AND
(tk.status = '${OperationStatus.EXPIRED}' OR tk.status = '${OperationStatus.FAILED}' OR tk.status = '${OperationStatus.ABORTED}') AND
jb."isCleaned" = FALSE`;
const sqlRes = (await this.query(query, [jobId])) as { unResettableTasks: string; failedTasks: string }[];
Expand Down
2 changes: 1 addition & 1 deletion src/DAL/repositories/taskRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EntityRepository, LessThan, Brackets, UpdateResult, In } from 'typeorm'
import { container } from 'tsyringe';
import { Logger } from '@map-colonies/js-logger';
import { ConflictError, NotFoundError } from '@map-colonies/error-types';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { SERVICES } from '../../common/constants';
import { TaskEntity } from '../entity/task';
import { TaskModelConvertor } from '../convertors/taskModelConvertor';
Expand All @@ -19,7 +20,6 @@ import {
ITaskType,
IUpdateTaskRequest,
} from '../../common/dataModels/tasks';
import { OperationStatus } from '../../common/dataModels/enums';
import { JobEntity } from '../entity/job';
import { IJobAndTaskStatus } from '../../common/interfaces';
import { GeneralRepository } from './generalRepository';
Expand Down
2 changes: 1 addition & 1 deletion src/DAL/repositories/transactionActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { singleton } from 'tsyringe';
import { ObjectType, QueryRunner } from 'typeorm';
import { BadRequestError } from '@map-colonies/error-types';
import { OperationStatus } from '../../common/dataModels/enums';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { ConnectionManager } from '../connectionManager';
import { JobRepository } from './jobRepository';
import { TaskRepository } from './taskRepository';
Expand Down
8 changes: 0 additions & 8 deletions src/common/dataModels/enums.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/common/dataModels/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//requests
import { OperationStatus } from './enums';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { GetTasksResponse, ICreateTaskBody } from './tasks';

export interface IJobsParams {
Expand Down
2 changes: 1 addition & 1 deletion src/common/dataModels/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OperationStatus } from './enums';
import { OperationStatus } from '@map-colonies/mc-priority-queue';

//requests
export interface IAllTasksParams {
Expand Down
2 changes: 1 addition & 1 deletion src/common/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { ResponseCodes } from './constants';
import { OperationStatus } from './dataModels/enums';

export interface IConfig {
get: <T>(setting: string) => T;
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/models/jobManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NotFoundError } from '@map-colonies/error-types';
import { inject, injectable } from 'tsyringe';
import { Tracer } from '@opentelemetry/api';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { SERVICES } from '../../common/constants';
import { ConnectionManager } from '../../DAL/connectionManager';
import {
Expand All @@ -21,7 +22,6 @@ import {
} from '../../common/dataModels/jobs';
import { JobParameters, JobRepository } from '../../DAL/repositories/jobRepository';
import { TransactionActions } from '../../DAL/repositories/transactionActions';
import { OperationStatus } from '../../common/dataModels/enums';

@injectable()
export class JobManager {
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/models/taskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NotFoundError } from '@map-colonies/error-types';
import { Tracer } from '@opentelemetry/api';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import { inject, injectable } from 'tsyringe';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { SERVICES } from '../../common/constants';
import { ConnectionManager } from '../../DAL/connectionManager';
import { TaskRepository } from '../../DAL/repositories/taskRepository';
Expand All @@ -17,7 +18,6 @@ import {
ISpecificTaskParams,
IUpdateTaskRequest,
} from '../../common/dataModels/tasks';
import { OperationStatus } from '../../common/dataModels/enums';
import { JobManager } from './jobManager';

@injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/taskManagement/models/taskManagementManger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { NotFoundError, BadRequestError } from '@map-colonies/error-types';
import { Tracer } from '@opentelemetry/api';
import { withSpanAsyncV4 } from '@map-colonies/telemetry';
import { inject, injectable } from 'tsyringe';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { SERVICES } from '../../common/constants';
import { ConnectionManager } from '../../DAL/connectionManager';
import { TaskRepository } from '../../DAL/repositories/taskRepository';
import { IFindInactiveTasksRequest, IGetTaskResponse, IRetrieveAndStartRequest } from '../../common/dataModels/tasks';
import { JobRepository } from '../../DAL/repositories/jobRepository';
import { OperationStatus } from '../../common/dataModels/enums';
import { IJobsParams, IJobsQuery } from '../../common/dataModels/jobs';

@injectable()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/jobs/jobs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import httpStatusCodes from 'http-status-codes';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { getContainerConfig, resetContainer } from '../testContainerConfig';
import { JobParameters, JobRepository } from '../../../src/DAL/repositories/jobRepository';
import { JobEntity } from '../../../src/DAL/entity/job';
Expand All @@ -15,7 +16,6 @@ import {
import { getApp } from '../../../src/app';
import { FindJobsResponse, IAvailableActions, IGetJobResponse } from '../../../src/common/dataModels/jobs';
import { TaskRepository } from '../../../src/DAL/repositories/taskRepository';
import { OperationStatus } from '../../../src/common/dataModels/enums';
import { TaskEntity } from '../../../src/DAL/entity/task';
import { ResponseCodes } from '../../../src/common/constants';
import { JobManager } from '../../../src/jobs/models/jobManager';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/jobs/tasks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import httpStatusCodes from 'http-status-codes';
import { NotFoundError } from '@map-colonies/error-types';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { getContainerConfig, resetContainer } from '../testContainerConfig';
import { TaskRepository } from '../../../src/DAL/repositories/taskRepository';
import { TaskEntity } from '../../../src/DAL/entity/task';
Expand All @@ -9,7 +10,6 @@ import { ICreateTaskBody, IGetTaskResponse, IGetTasksStatus } from '../../../src
import { IFindTasksRequest } from '../../../src/common/dataModels/tasks';
import { JobEntity } from '../../../src/DAL/entity/job';

import { OperationStatus } from '../../../src/common/dataModels/enums';
import { getApp } from '../../../src/app';
import { ResponseCodes } from '../../../src/common/constants';
import { TasksRequestSender } from './helpers/tasksRequestSender';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/taskManagement/taskManagement.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import httpStatusCodes from 'http-status-codes';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { getContainerConfig, resetContainer } from '../testContainerConfig';
import { getApp } from '../../../src/app';
import { createJobAndTaskStatus, createUuid } from '../../mocks/values';
import { TaskRepository } from '../../../src/DAL/repositories/taskRepository';
import { JobRepository } from '../../../src/DAL/repositories/jobRepository';
import { registerRepository, initTypeOrmMocks, RepositoryMocks, In } from '../../mocks/DBMock';
import { OperationStatus } from '../../../src/common/dataModels/enums';
import { TaskEntity } from '../../../src/DAL/entity/task';
import { IGetTaskResponse } from '../../../src/common/dataModels/tasks';
import { ResponseCodes } from '../../../src/common/constants';
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randUuid } from '@ngneat/falso';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { IJobAndTaskStatus } from '../../src/common/interfaces';
import { OperationStatus } from '../../src/common/dataModels/enums';

export const createUuid = (): string => {
return randUuid();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/DAL/taskModelConverter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OperationStatus } from '../../../src/common/dataModels/enums';
import { OperationStatus } from '@map-colonies/mc-priority-queue';
import { IGetTaskResponse, IUpdateTaskRequest } from '../../../src/common/dataModels/tasks';
import { TaskModelConvertor } from '../../../src/DAL/convertors/taskModelConvertor';
import { TaskEntity } from '../../../src/DAL/entity/task';
Expand Down

0 comments on commit 1cb313a

Please sign in to comment.