Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added option for releaseInactive to not raise task attempts (MAPCO-5466) #46

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_and_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/release-on-tag-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"key": "",
"cert": ""
},
"database": "raster",
"database": "common",
"schema": "public",
"synchronize": false,
"logging": false,
Expand Down
9 changes: 9 additions & 0 deletions openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/taskIdList'
parameters:
- $ref: '#/components/parameters/shouldRaiseAttempts'
responses:
'200':
description: OK
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/DAL/repositories/taskRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class TaskRepository extends GeneralRepository<TaskEntity> {
return this.taskConvertor.entityToModel(entity);
}

public async releaseInactiveTask(taskIds: string[]): Promise<string[]> {
public async releaseInactiveTask(taskIds: string[], shouldRaiseAttempts: boolean): Promise<string[]> {
const getJobStatusQuery = `
SELECT task.id as "taskId", "jobId", task.status as "taskStatus", job.status as "jobStatus"
FROM "Job" job, "Task" task
Expand All @@ -166,14 +166,14 @@ export class TaskRepository extends GeneralRepository<TaskEntity> {
// 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);
}

Expand Down Expand Up @@ -306,10 +306,10 @@ export class TaskRepository extends GeneralRepository<TaskEntity> {
}
}

private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus): Promise<void> {
private async updateTaskStatus(taskIds: string[], newStatus: OperationStatus, shouldRaiseAttempts: boolean): Promise<void> {
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)
Expand Down
4 changes: 4 additions & 0 deletions src/common/dataModels/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export interface IFindInactiveTasksRequest {
ignoreTypes?: ITaskType[];
}

export interface IReleaseInactiveQueryParams {
shouldRaiseAttempts?: boolean;
}

//responses
export interface IGetTaskResponse {
id: string;
Expand Down
6 changes: 3 additions & 3 deletions src/taskManagement/controllers/taskManagementController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRetrieveAndStartRequest, IGetTaskResponse | ErrorResponse>;
type ReleaseInactiveTasksHandler = RequestHandler<undefined, string[], string[]>;
type ReleaseInactiveTasksHandler = RequestHandler<undefined, string[], string[], IReleaseInactiveQueryParams>;
type FindInactiveTasksHandler = RequestHandler<undefined, string[], IFindInactiveTasksRequest>;
type UpdateExpiredStatusHandler = RequestHandler<undefined, DefaultResponse>;
type AbortHandler = RequestHandler<IJobsParams, DefaultResponse, undefined, IJobsQuery>;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/taskManagement/models/taskManagementManger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class TaskManagementManager {
) {}

@withSpanAsyncV4
public async releaseInactive(tasks: string[]): Promise<string[]> {
public async releaseInactive(tasks: string[], shouldRaiseAttempts?: boolean): Promise<string[]> {
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;
}
Expand Down
Loading