Skip to content

Commit

Permalink
feat(be): 🚀 update worker name for tracking & monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
lehuygiang28 committed Jun 11, 2024
1 parent bc7dd42 commit a45c2e1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/be/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ REDIS_CONNECT_TIMEOUT=5000

# OPTIONAL

BULL_NAME='tasktr'
BULL_TASK_CONCURRENCY=20
BULL_BACKGROUND_CONCURRENCY=10
BULL_SAVE_LOG_CONCURRENCY=10
Expand Down
3 changes: 3 additions & 0 deletions apps/be/common/src/bullmq/task-log.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export class TaskLogProcessor extends WorkerHost implements OnModuleInit {
async saveTaskLog(job: Job<unknown, unknown, TaskJobName>): Promise<boolean> {
try {
const res = await this.taskLogsService.create(job.data as CreateTaskLogDto);
if (res) {
this.logger.info(`Saved task log: ${res._id}`);
}
return !!res;
} catch (error) {
this.logger.error(`Error saving task log: ${error}`);
Expand Down
1 change: 1 addition & 0 deletions apps/be/common/src/bullmq/task.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class TaskProcessor extends WorkerHost implements OnModuleInit {
taskId: job.data._id,
endpoint,
method,
workerName: process.env['BULL_NAME'] ?? 'default',
scheduledAt: new Date(job?.processedOn ?? now),
executedAt: new Date(job?.finishedOn ?? now),
duration: 0,
Expand Down
4 changes: 4 additions & 0 deletions apps/be/src/app/task-logs/dtos/task-log.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class TaskLogDto implements TaskLog {
@IsNumber()
statusCode: number;

@ApiProperty({ type: String })
@IsString()
workerName: string;

@ApiProperty({ type: Date, required: false })
@IsDate()
@IsOptional()
Expand Down
3 changes: 3 additions & 0 deletions apps/be/src/app/task-logs/task-log.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class TaskLog extends AbstractDocument {
@Prop({ required: true, type: Date })
executedAt: Date;

@Prop({ required: false, default: '' })
workerName: string;

@Prop({ required: false, default: new Date() })
createdAt?: Date;

Expand Down

0 comments on commit a45c2e1

Please sign in to comment.