From ee9709384bcbe52b9ef80415903967dcff557343 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 09:51:32 -0400 Subject: [PATCH 1/8] [TM-1536] add total_content and proccessed_content field to delayedJob response --- .../job-service/src/jobs/dto/delayed-job.dto.ts | 17 +++++++++++++++-- .../src/lib/entities/delayed-job.entity.ts | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/job-service/src/jobs/dto/delayed-job.dto.ts b/apps/job-service/src/jobs/dto/delayed-job.dto.ts index 6874ef4f..f522136d 100644 --- a/apps/job-service/src/jobs/dto/delayed-job.dto.ts +++ b/apps/job-service/src/jobs/dto/delayed-job.dto.ts @@ -10,8 +10,8 @@ type Status = (typeof STATUSES)[number]; @JsonApiDto({ type: 'delayedJobs' }) export class DelayedJobDto extends JsonApiAttributes { constructor(job: DelayedJob) { - const { status, statusCode, payload } = job; - super({ status, statusCode, payload }); + const { status, statusCode, payload, processed_content, total_content } = job; + super({ status, statusCode, payload, processed_content, total_content }); } @ApiProperty({ @@ -31,4 +31,17 @@ export class DelayedJobDto extends JsonApiAttributes { nullable: true }) payload: object | null; + + + @ApiProperty({ + description: 'If the job is in progress, this is the total content to process', + nullable: true + }) + total_content: number | null; + + @ApiProperty({ + description: 'If the job is in progress, this is the total content processed', + nullable: true + }) + processed_content: number | null; } diff --git a/libs/database/src/lib/entities/delayed-job.entity.ts b/libs/database/src/lib/entities/delayed-job.entity.ts index 147dd955..0b09e62d 100644 --- a/libs/database/src/lib/entities/delayed-job.entity.ts +++ b/libs/database/src/lib/entities/delayed-job.entity.ts @@ -32,4 +32,12 @@ export class DelayedJob extends Model { @AllowNull @Column(JSON) payload: object | null; + + @AllowNull + @Column(JSON) + total_content: number | null; + + @AllowNull + @Column(JSON) + processed_content: number | null; } From 4203aeb10624e160786fe787e6b5e7f136a7d7e6 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:17:16 -0400 Subject: [PATCH 2/8] [TM-1536] add proccess message field --- apps/job-service/src/jobs/dto/delayed-job.dto.ts | 10 ++++++++-- libs/database/src/lib/entities/delayed-job.entity.ts | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/job-service/src/jobs/dto/delayed-job.dto.ts b/apps/job-service/src/jobs/dto/delayed-job.dto.ts index 437778d1..6665de84 100644 --- a/apps/job-service/src/jobs/dto/delayed-job.dto.ts +++ b/apps/job-service/src/jobs/dto/delayed-job.dto.ts @@ -8,8 +8,8 @@ type Status = (typeof STATUSES)[number]; @JsonApiDto({ type: "delayedJobs" }) export class DelayedJobDto extends JsonApiAttributes { constructor(job: DelayedJob) { - const { status, statusCode, payload, processed_content, total_content } = job; - super({ status, statusCode, payload, processed_content, total_content }); + const { status, statusCode, payload, processed_content, total_content, proccess_message } = job; + super({ status, statusCode, payload, processed_content, total_content, proccess_message }); } @ApiProperty({ @@ -43,4 +43,10 @@ export class DelayedJobDto extends JsonApiAttributes { nullable: true }) processed_content: number | null; + + @ApiProperty({ + description: 'If the job is in progress, this is the proccess message', + nullable: true + }) + proccess_message: string | null } diff --git a/libs/database/src/lib/entities/delayed-job.entity.ts b/libs/database/src/lib/entities/delayed-job.entity.ts index f69311fd..caac7061 100644 --- a/libs/database/src/lib/entities/delayed-job.entity.ts +++ b/libs/database/src/lib/entities/delayed-job.entity.ts @@ -31,4 +31,8 @@ export class DelayedJob extends Model { @AllowNull @Column(JSON) processed_content: number | null; + + @AllowNull + @Column + proccess_message: string | null } From 8efb6d9e22b4ee70a09e68d6c7a8ca26a45bd1bf Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:19:46 -0400 Subject: [PATCH 3/8] changes --- apps/job-service/src/jobs/dto/delayed-job.dto.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/job-service/src/jobs/dto/delayed-job.dto.ts b/apps/job-service/src/jobs/dto/delayed-job.dto.ts index 6665de84..565bb62d 100644 --- a/apps/job-service/src/jobs/dto/delayed-job.dto.ts +++ b/apps/job-service/src/jobs/dto/delayed-job.dto.ts @@ -31,7 +31,6 @@ export class DelayedJobDto extends JsonApiAttributes { }) payload: object | null; - @ApiProperty({ description: 'If the job is in progress, this is the total content to process', nullable: true From 5371fac07209ea680129c1a73ea0d6e86e11221b Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:26:22 -0400 Subject: [PATCH 4/8] [TM-1536] add import to delayed job --- apps/job-service/src/jobs/dto/delayed-job.dto.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/job-service/src/jobs/dto/delayed-job.dto.ts b/apps/job-service/src/jobs/dto/delayed-job.dto.ts index 565bb62d..e7ab2bdc 100644 --- a/apps/job-service/src/jobs/dto/delayed-job.dto.ts +++ b/apps/job-service/src/jobs/dto/delayed-job.dto.ts @@ -1,6 +1,7 @@ import { JsonApiAttributes } from "@terramatch-microservices/common/dto/json-api-attributes"; import { JsonApiDto } from "@terramatch-microservices/common/decorators"; import { ApiProperty } from "@nestjs/swagger"; +import { DelayedJob } from "@terramatch-microservices/database/entities"; const STATUSES = ["pending", "failed", "succeeded"]; type Status = (typeof STATUSES)[number]; From 8024d34ce17ef7b306519384b5c83f88fbc415f1 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:33:41 -0400 Subject: [PATCH 5/8] [TM-1536] add column type --- libs/database/src/lib/entities/delayed-job.entity.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/database/src/lib/entities/delayed-job.entity.ts b/libs/database/src/lib/entities/delayed-job.entity.ts index caac7061..1fc24f92 100644 --- a/libs/database/src/lib/entities/delayed-job.entity.ts +++ b/libs/database/src/lib/entities/delayed-job.entity.ts @@ -25,14 +25,14 @@ export class DelayedJob extends Model { payload: object | null; @AllowNull - @Column(JSON) + @Column(INTEGER) total_content: number | null; @AllowNull - @Column(JSON) + @Column(INTEGER) processed_content: number | null; @AllowNull - @Column + @Column(STRING) proccess_message: string | null } From 1ef94ed796fc50d9fced709bb49eb82ba2a2628a Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:42:59 -0400 Subject: [PATCH 6/8] fix test --- libs/database/src/lib/factories/delayed-job.factory.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/database/src/lib/factories/delayed-job.factory.ts b/libs/database/src/lib/factories/delayed-job.factory.ts index d7c0a6ca..14823210 100644 --- a/libs/database/src/lib/factories/delayed-job.factory.ts +++ b/libs/database/src/lib/factories/delayed-job.factory.ts @@ -5,5 +5,8 @@ export const DelayedJobFactory = FactoryGirl.define(DelayedJob, async () => ({ uuid: crypto.randomUUID(), status: 'succeeded', statusCode: 200, - payload: { "data": "test" } + payload: { "data": "test" }, + total_content: 0, + processed_content: 0, + proccess_message: "test" })); From c09f01ac709d847650fb4ad0339726e89a1c0e1a Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 13:59:54 -0400 Subject: [PATCH 7/8] test --- apps/job-service/src/jobs/delayed-jobs.controller.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts b/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts index 86cbb88e..e6b92224 100644 --- a/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts +++ b/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts @@ -32,5 +32,8 @@ describe('DelayedJobsController', () => { expect(resource.id).toBe(uuid); expect(resource.attributes.statusCode).toBe(statusCode); expect(resource.attributes.payload).toMatchObject(payload); + expect(resource.attributes.total_content).toBe(payload); + expect(resource.attributes.processed_content).toBe(payload); + expect(resource.attributes.proccess_message).toBe(payload); }); }) From 210ab142d0664e89c2ef5342f4efec7789aff8d0 Mon Sep 17 00:00:00 2001 From: Limber Mamani Date: Mon, 2 Dec 2024 14:06:26 -0400 Subject: [PATCH 8/8] fix --- apps/job-service/src/jobs/delayed-jobs.controller.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts b/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts index e6b92224..ebbd1a29 100644 --- a/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts +++ b/apps/job-service/src/jobs/delayed-jobs.controller.spec.ts @@ -25,15 +25,15 @@ describe('DelayedJobsController', () => { }); it('should return the job definition when the delayed job does exist', async () => { - const { uuid, statusCode, payload } = await DelayedJobFactory.create(); + const { uuid, statusCode, payload, total_content, processed_content, proccess_message } = await DelayedJobFactory.create(); const result = await controller.findOne(uuid); const resource = result.data as Resource; expect(resource.type).toBe('delayedJobs'); expect(resource.id).toBe(uuid); expect(resource.attributes.statusCode).toBe(statusCode); expect(resource.attributes.payload).toMatchObject(payload); - expect(resource.attributes.total_content).toBe(payload); - expect(resource.attributes.processed_content).toBe(payload); - expect(resource.attributes.proccess_message).toBe(payload); + expect(resource.attributes.total_content).toBe(total_content); + expect(resource.attributes.processed_content).toBe(processed_content); + expect(resource.attributes.proccess_message).toBe(proccess_message); }); })