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..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,12 +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(total_content); + expect(resource.attributes.processed_content).toBe(processed_content); + expect(resource.attributes.proccess_message).toBe(proccess_message); }); }) 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 8fbab5d3..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,12 +1,18 @@ 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]; @JsonApiDto({ type: "delayedJobs" }) export class DelayedJobDto extends JsonApiAttributes { + constructor(job: DelayedJob) { + const { status, statusCode, payload, processed_content, total_content, proccess_message } = job; + super({ status, statusCode, payload, processed_content, total_content, proccess_message }); + } + @ApiProperty({ description: "The current status of the job. If the status is not pending, the payload and statusCode will be provided.", @@ -25,4 +31,22 @@ 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; + + @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 5ced0ade..1fc24f92 100644 --- a/libs/database/src/lib/entities/delayed-job.entity.ts +++ b/libs/database/src/lib/entities/delayed-job.entity.ts @@ -23,4 +23,16 @@ export class DelayedJob extends Model { @AllowNull @Column(JSON) payload: object | null; + + @AllowNull + @Column(INTEGER) + total_content: number | null; + + @AllowNull + @Column(INTEGER) + processed_content: number | null; + + @AllowNull + @Column(STRING) + proccess_message: string | null } 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" }));