Skip to content

Commit

Permalink
Merge pull request #20 from wri/TM-1536_delayed_job_progress
Browse files Browse the repository at this point in the history
[TM-1536] add total_content and proccessed_content field to delayedJo…
  • Loading branch information
LimberHope authored Dec 2, 2024
2 parents 6156e11 + 210ab14 commit d24ee38
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/job-service/src/jobs/delayed-jobs.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
})
24 changes: 24 additions & 0 deletions apps/job-service/src/jobs/dto/delayed-job.dto.ts
Original file line number Diff line number Diff line change
@@ -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<DelayedJobDto> {
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.",
Expand All @@ -25,4 +31,22 @@ export class DelayedJobDto extends JsonApiAttributes<DelayedJobDto> {
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
}
12 changes: 12 additions & 0 deletions libs/database/src/lib/entities/delayed-job.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ export class DelayedJob extends Model<DelayedJob> {
@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
}
5 changes: 4 additions & 1 deletion libs/database/src/lib/factories/delayed-job.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}));

0 comments on commit d24ee38

Please sign in to comment.