From abf055cd4380078bca4a9b166a0d48645578fd93 Mon Sep 17 00:00:00 2001 From: Nitzan Morr Date: Sun, 24 Nov 2024 11:07:36 +0200 Subject: [PATCH 1/4] feat: added option for releaseInactive to not raise task attempts --- config/default.json | 2 +- openapi3.yaml | 9 +++++++++ src/DAL/repositories/taskRepository.ts | 10 +++++----- src/common/dataModels/tasks.ts | 4 ++++ .../controllers/taskManagementController.ts | 6 +++--- src/taskManagement/models/taskManagementManger.ts | 4 ++-- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/config/default.json b/config/default.json index 5658b94..204bfd6 100644 --- a/config/default.json +++ b/config/default.json @@ -42,7 +42,7 @@ "key": "", "cert": "" }, - "database": "raster", + "database": "common", "schema": "public", "synchronize": false, "logging": false, diff --git a/openapi3.yaml b/openapi3.yaml index 9ce9f77..465088b 100644 --- a/openapi3.yaml +++ b/openapi3.yaml @@ -494,6 +494,8 @@ paths: application/json: schema: $ref: '#/components/schemas/taskIdList' + parameters: + - $ref: '#/components/parameters/raiseAttempts' responses: '200': description: OK @@ -688,6 +690,13 @@ components: schema: type: string format: uuid + raiseAttempts: + in: query + name: raiseAttempts + description: whether or not to raise task attempts on release + required: false + schema: + type: boolean schemas: getJobsByCriteria: type: object diff --git a/src/DAL/repositories/taskRepository.ts b/src/DAL/repositories/taskRepository.ts index 7f7b236..0a5ac10 100644 --- a/src/DAL/repositories/taskRepository.ts +++ b/src/DAL/repositories/taskRepository.ts @@ -141,7 +141,7 @@ export class TaskRepository extends GeneralRepository { return this.taskConvertor.entityToModel(entity); } - public async releaseInactiveTask(taskIds: string[]): Promise { + public async releaseInactiveTask(taskIds: string[], raiseAttempts: boolean): Promise { const getJobStatusQuery = ` SELECT task.id as "taskId", "jobId", task.status as "taskStatus", job.status as "jobStatus" FROM "Job" job, "Task" task @@ -166,14 +166,14 @@ export class TaskRepository extends GeneralRepository { // Execute update query for Pending status if (pendingEntities.length > 0) { const pendingTaskIds = pendingEntities.map((entity) => entity.taskId); - await this.updateTaskStatus(pendingTaskIds, OperationStatus.PENDING); + await this.updateTaskStatus(pendingTaskIds, OperationStatus.PENDING, raiseAttempts); updatedIds.push(...pendingTaskIds); } // Execute update query for Aborted status if (abortedEntities.length > 0) { const abortedTaskIds = abortedEntities.map((entity) => entity.taskId); - await this.updateTaskStatus(abortedTaskIds, OperationStatus.ABORTED); + await this.updateTaskStatus(abortedTaskIds, OperationStatus.ABORTED, raiseAttempts); updatedIds.push(...abortedTaskIds); } @@ -306,10 +306,10 @@ export class TaskRepository extends GeneralRepository { } } - private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus): Promise { + private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus, raiseAttempts: boolean): Promise { await this.createQueryBuilder() .update() - .set({ status: newStatus, attempts: () => 'attempts + 1' }) + .set({ status: newStatus, attempts: () => (raiseAttempts ? 'attempts + 1' : 'attempts') }) .where({ id: In(taskIds) }) .returning('id') .updateEntity(true) diff --git a/src/common/dataModels/tasks.ts b/src/common/dataModels/tasks.ts index 28c3cc2..5944c2c 100644 --- a/src/common/dataModels/tasks.ts +++ b/src/common/dataModels/tasks.ts @@ -51,6 +51,10 @@ export interface IFindInactiveTasksRequest { ignoreTypes?: ITaskType[]; } +export interface IReleaseInactiveQuery { + raiseAttempts?: boolean; +} + //responses export interface IGetTaskResponse { id: string; diff --git a/src/taskManagement/controllers/taskManagementController.ts b/src/taskManagement/controllers/taskManagementController.ts index 56eb75c..62628cf 100644 --- a/src/taskManagement/controllers/taskManagementController.ts +++ b/src/taskManagement/controllers/taskManagementController.ts @@ -5,13 +5,13 @@ import { ErrorResponse } from '@map-colonies/error-express-handler'; import httpStatus from 'http-status-codes'; import { injectable, inject } from 'tsyringe'; import { ResponseCodes, SERVICES } from '../../common/constants'; -import { IFindInactiveTasksRequest, IGetTaskResponse, IRetrieveAndStartRequest } from '../../common/dataModels/tasks'; +import { IFindInactiveTasksRequest, IGetTaskResponse, IReleaseInactiveQuery, IRetrieveAndStartRequest } from '../../common/dataModels/tasks'; import { DefaultResponse } from '../../common/interfaces'; import { TaskManagementManager } from '../models/taskManagementManger'; import { IJobsParams, IJobsQuery } from '../../common/dataModels/jobs'; type RetrieveAndStartHandler = RequestHandler; -type ReleaseInactiveTasksHandler = RequestHandler; +type ReleaseInactiveTasksHandler = RequestHandler; type FindInactiveTasksHandler = RequestHandler; type UpdateExpiredStatusHandler = RequestHandler; type AbortHandler = RequestHandler; @@ -38,7 +38,7 @@ export class TaskManagementController { public releaseInactive: ReleaseInactiveTasksHandler = async (req, res, next) => { try { - const releasedIds = await this.manager.releaseInactive(req.body); + const releasedIds = await this.manager.releaseInactive(req.body, req.query.raiseAttempts); return res.status(httpStatus.OK).json(releasedIds); } catch (err) { return next(err); diff --git a/src/taskManagement/models/taskManagementManger.ts b/src/taskManagement/models/taskManagementManger.ts index a8c02d2..b8442bf 100644 --- a/src/taskManagement/models/taskManagementManger.ts +++ b/src/taskManagement/models/taskManagementManger.ts @@ -23,10 +23,10 @@ export class TaskManagementManager { ) {} @withSpanAsyncV4 - public async releaseInactive(tasks: string[]): Promise { + public async releaseInactive(tasks: string[], raiseAttempts?: boolean): Promise { const repo = await this.getTaskRepository(); this.logger.info(`trying to release dead tasks: ${tasks.join(',')}`); - const releasedTasks = await repo.releaseInactiveTask(tasks); + const releasedTasks = await repo.releaseInactiveTask(tasks, raiseAttempts ?? true); this.logger.info(`released dead tasks: ${releasedTasks.join(',')}`); return releasedTasks; } From 94d0166fa8440f2b481bedcf7d21b8f47f735ea7 Mon Sep 17 00:00:00 2001 From: Nitzan Morr Date: Sun, 24 Nov 2024 13:04:21 +0200 Subject: [PATCH 2/4] ci: upgraded shared workflows to v2 --- .github/workflows/build_and_push.yaml | 4 ++-- .github/workflows/pull_request.yaml | 2 +- .github/workflows/release-on-tag-push.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_push.yaml b/.github/workflows/build_and_push.yaml index 5e62827..1a290f0 100644 --- a/.github/workflows/build_and_push.yaml +++ b/.github/workflows/build_and_push.yaml @@ -19,9 +19,9 @@ permissions: jobs: build_and_push_docker: - uses: MapColonies/shared-workflows/.github/workflows/build-and-push-docker.yaml@v1 + uses: MapColonies/shared-workflows/.github/workflows/build-and-push-docker.yaml@v2 secrets: inherit build_and_push_helm: - uses: MapColonies/shared-workflows/.github/workflows/build-and-push-helm.yaml@v1 + uses: MapColonies/shared-workflows/.github/workflows/build-and-push-helm.yaml@v2 secrets: inherit diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 63d6fb6..69dcebc 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -4,5 +4,5 @@ on: [pull_request] jobs: pull_request: - uses: MapColonies/shared-workflows/.github/workflows/pull_request.yaml@v1 + uses: MapColonies/shared-workflows/.github/workflows/pull_request.yaml@v2 secrets: inherit diff --git a/.github/workflows/release-on-tag-push.yaml b/.github/workflows/release-on-tag-push.yaml index 698ab3a..7f9b9a3 100644 --- a/.github/workflows/release-on-tag-push.yaml +++ b/.github/workflows/release-on-tag-push.yaml @@ -7,5 +7,5 @@ on: jobs: release_on_tag_push: - uses: MapColonies/shared-workflows/.github/workflows/release-on-tag-push.yaml@v1 + uses: MapColonies/shared-workflows/.github/workflows/release-on-tag-push.yaml@v2 secrets: inherit From c90905aecfc934b24b6fd98fc04565985622e25e Mon Sep 17 00:00:00 2001 From: Nitzan Morr Date: Sun, 24 Nov 2024 13:15:26 +0200 Subject: [PATCH 3/4] fix: change raiseAttempts parameter name to shouldRaiseAttempts --- openapi3.yaml | 6 +++--- src/DAL/repositories/taskRepository.ts | 10 +++++----- src/common/dataModels/tasks.ts | 2 +- .../controllers/taskManagementController.ts | 2 +- src/taskManagement/models/taskManagementManger.ts | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openapi3.yaml b/openapi3.yaml index 465088b..5b340e3 100644 --- a/openapi3.yaml +++ b/openapi3.yaml @@ -495,7 +495,7 @@ paths: schema: $ref: '#/components/schemas/taskIdList' parameters: - - $ref: '#/components/parameters/raiseAttempts' + - $ref: '#/components/parameters/shouldRaiseAttempts' responses: '200': description: OK @@ -690,9 +690,9 @@ components: schema: type: string format: uuid - raiseAttempts: + shouldRaiseAttempts: in: query - name: raiseAttempts + name: shouldRaiseAttempts description: whether or not to raise task attempts on release required: false schema: diff --git a/src/DAL/repositories/taskRepository.ts b/src/DAL/repositories/taskRepository.ts index 0a5ac10..24ef4f3 100644 --- a/src/DAL/repositories/taskRepository.ts +++ b/src/DAL/repositories/taskRepository.ts @@ -141,7 +141,7 @@ export class TaskRepository extends GeneralRepository { return this.taskConvertor.entityToModel(entity); } - public async releaseInactiveTask(taskIds: string[], raiseAttempts: boolean): Promise { + public async releaseInactiveTask(taskIds: string[], shouldRaiseAttempts: boolean): Promise { const getJobStatusQuery = ` SELECT task.id as "taskId", "jobId", task.status as "taskStatus", job.status as "jobStatus" FROM "Job" job, "Task" task @@ -166,14 +166,14 @@ export class TaskRepository extends GeneralRepository { // Execute update query for Pending status if (pendingEntities.length > 0) { const pendingTaskIds = pendingEntities.map((entity) => entity.taskId); - await this.updateTaskStatus(pendingTaskIds, OperationStatus.PENDING, raiseAttempts); + await this.updateTaskStatus(pendingTaskIds, OperationStatus.PENDING, shouldRaiseAttempts); updatedIds.push(...pendingTaskIds); } // Execute update query for Aborted status if (abortedEntities.length > 0) { const abortedTaskIds = abortedEntities.map((entity) => entity.taskId); - await this.updateTaskStatus(abortedTaskIds, OperationStatus.ABORTED, raiseAttempts); + await this.updateTaskStatus(abortedTaskIds, OperationStatus.ABORTED, shouldRaiseAttempts); updatedIds.push(...abortedTaskIds); } @@ -306,10 +306,10 @@ export class TaskRepository extends GeneralRepository { } } - private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus, raiseAttempts: boolean): Promise { + private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus, shouldRaiseAttempts: boolean): Promise { await this.createQueryBuilder() .update() - .set({ status: newStatus, attempts: () => (raiseAttempts ? 'attempts + 1' : 'attempts') }) + .set({ status: newStatus, attempts: () => (shouldRaiseAttempts ? 'attempts + 1' : 'attempts') }) .where({ id: In(taskIds) }) .returning('id') .updateEntity(true) diff --git a/src/common/dataModels/tasks.ts b/src/common/dataModels/tasks.ts index 5944c2c..751534b 100644 --- a/src/common/dataModels/tasks.ts +++ b/src/common/dataModels/tasks.ts @@ -52,7 +52,7 @@ export interface IFindInactiveTasksRequest { } export interface IReleaseInactiveQuery { - raiseAttempts?: boolean; + shouldRaiseAttempts?: boolean; } //responses diff --git a/src/taskManagement/controllers/taskManagementController.ts b/src/taskManagement/controllers/taskManagementController.ts index 62628cf..b65babe 100644 --- a/src/taskManagement/controllers/taskManagementController.ts +++ b/src/taskManagement/controllers/taskManagementController.ts @@ -38,7 +38,7 @@ export class TaskManagementController { public releaseInactive: ReleaseInactiveTasksHandler = async (req, res, next) => { try { - const releasedIds = await this.manager.releaseInactive(req.body, req.query.raiseAttempts); + const releasedIds = await this.manager.releaseInactive(req.body, req.query.shouldRaiseAttempts); return res.status(httpStatus.OK).json(releasedIds); } catch (err) { return next(err); diff --git a/src/taskManagement/models/taskManagementManger.ts b/src/taskManagement/models/taskManagementManger.ts index b8442bf..5cefbfe 100644 --- a/src/taskManagement/models/taskManagementManger.ts +++ b/src/taskManagement/models/taskManagementManger.ts @@ -23,10 +23,10 @@ export class TaskManagementManager { ) {} @withSpanAsyncV4 - public async releaseInactive(tasks: string[], raiseAttempts?: boolean): Promise { + public async releaseInactive(tasks: string[], shouldRaiseAttempts?: boolean): Promise { const repo = await this.getTaskRepository(); this.logger.info(`trying to release dead tasks: ${tasks.join(',')}`); - const releasedTasks = await repo.releaseInactiveTask(tasks, raiseAttempts ?? true); + const releasedTasks = await repo.releaseInactiveTask(tasks, shouldRaiseAttempts ?? true); this.logger.info(`released dead tasks: ${releasedTasks.join(',')}`); return releasedTasks; } From e734c77745af9c40bf883c55bd0013980f3e0fc1 Mon Sep 17 00:00:00 2001 From: Nitzan Morr Date: Sun, 24 Nov 2024 14:15:30 +0200 Subject: [PATCH 4/4] refactor: changed IReleaseInactiveQuery to IReleaseInactiveQueryParams --- src/common/dataModels/tasks.ts | 2 +- src/taskManagement/controllers/taskManagementController.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/dataModels/tasks.ts b/src/common/dataModels/tasks.ts index 751534b..208fd40 100644 --- a/src/common/dataModels/tasks.ts +++ b/src/common/dataModels/tasks.ts @@ -51,7 +51,7 @@ export interface IFindInactiveTasksRequest { ignoreTypes?: ITaskType[]; } -export interface IReleaseInactiveQuery { +export interface IReleaseInactiveQueryParams { shouldRaiseAttempts?: boolean; } diff --git a/src/taskManagement/controllers/taskManagementController.ts b/src/taskManagement/controllers/taskManagementController.ts index b65babe..2eafe96 100644 --- a/src/taskManagement/controllers/taskManagementController.ts +++ b/src/taskManagement/controllers/taskManagementController.ts @@ -5,13 +5,13 @@ import { ErrorResponse } from '@map-colonies/error-express-handler'; import httpStatus from 'http-status-codes'; import { injectable, inject } from 'tsyringe'; import { ResponseCodes, SERVICES } from '../../common/constants'; -import { IFindInactiveTasksRequest, IGetTaskResponse, IReleaseInactiveQuery, IRetrieveAndStartRequest } from '../../common/dataModels/tasks'; +import { IFindInactiveTasksRequest, IGetTaskResponse, IReleaseInactiveQueryParams, IRetrieveAndStartRequest } from '../../common/dataModels/tasks'; import { DefaultResponse } from '../../common/interfaces'; import { TaskManagementManager } from '../models/taskManagementManger'; import { IJobsParams, IJobsQuery } from '../../common/dataModels/jobs'; type RetrieveAndStartHandler = RequestHandler; -type ReleaseInactiveTasksHandler = RequestHandler; +type ReleaseInactiveTasksHandler = RequestHandler; type FindInactiveTasksHandler = RequestHandler; type UpdateExpiredStatusHandler = RequestHandler; type AbortHandler = RequestHandler;