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

[TM-1536] add total_content and proccessed_content field to delayedJo… #20

Merged
merged 9 commits into from
Dec 2, 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
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 });
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added? It should not be necessary.


@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"
}));
Loading