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 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..5b340e3 100644 --- a/openapi3.yaml +++ b/openapi3.yaml @@ -494,6 +494,8 @@ paths: application/json: schema: $ref: '#/components/schemas/taskIdList' + parameters: + - $ref: '#/components/parameters/shouldRaiseAttempts' responses: '200': description: OK @@ -688,6 +690,13 @@ components: schema: type: string format: uuid + shouldRaiseAttempts: + in: query + name: shouldRaiseAttempts + 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..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[]): 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); + 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); + 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): Promise { + private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus, shouldRaiseAttempts: boolean): Promise { await this.createQueryBuilder() .update() - .set({ status: newStatus, attempts: () => 'attempts + 1' }) + .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 28c3cc2..208fd40 100644 --- a/src/common/dataModels/tasks.ts +++ b/src/common/dataModels/tasks.ts @@ -51,6 +51,10 @@ export interface IFindInactiveTasksRequest { ignoreTypes?: ITaskType[]; } +export interface IReleaseInactiveQueryParams { + shouldRaiseAttempts?: boolean; +} + //responses export interface IGetTaskResponse { id: string; diff --git a/src/taskManagement/controllers/taskManagementController.ts b/src/taskManagement/controllers/taskManagementController.ts index 56eb75c..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, 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; @@ -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.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 a8c02d2..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[]): 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); + const releasedTasks = await repo.releaseInactiveTask(tasks, shouldRaiseAttempts ?? true); this.logger.info(`released dead tasks: ${releasedTasks.join(',')}`); return releasedTasks; }