Skip to content

Commit

Permalink
🐛 FIX: Should show queue size on logging (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Aug 8, 2022
1 parent 3a41b21 commit 7106807
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/core/service/TaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export class TaskService extends AbstractService {
return existsTask;
}
await this.taskRepository.saveTask(task);
const queueSize = await this.queueAdapter.push<string>(task.type, task.taskId);
await this.queueAdapter.push<string>(task.type, task.taskId);
const queueLength = await this.getTaskQueueLength(task.type);
this.logger.info('[TaskService.createTask:new] taskType: %s, targetName: %s, taskId: %s, queue size: %s',
task.type, task.targetName, task.taskId, queueSize);
task.type, task.targetName, task.taskId, queueLength);
return task;
}

Expand All @@ -54,9 +55,10 @@ export class TaskService extends AbstractService {
// make sure updatedAt changed
task.updatedAt = new Date();
await this.taskRepository.saveTask(task);
const queueSize = await this.queueAdapter.push<string>(task.type, task.taskId);
await this.queueAdapter.push<string>(task.type, task.taskId);
const queueLength = await this.getTaskQueueLength(task.type);
this.logger.info('[TaskService.retryTask:save] taskType: %s, targetName: %s, taskId: %s, queue size: %s',
task.type, task.targetName, task.taskId, queueSize);
task.type, task.targetName, task.taskId, queueLength);
}

public async findTask(taskId: string) {
Expand Down
2 changes: 2 additions & 0 deletions test/core/service/TaskService/findExecuteTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ describe('test/core/service/TaskService/findExecuteTask.test.ts', () => {

const newTask = await packageSyncerService.createTask('foo');
assert(newTask);
app.expectLog(/queue size: 1/);
assert(!newTask.data.taskWorker);
// same task not create again
const newTask2 = await packageSyncerService.createTask('foo');
assert(newTask2);
assert(newTask2.taskId === newTask.taskId);
assert(!newTask2.data.taskWorker);
app.expectLog(/queue size: 1/);

// find other task type
task = await taskService.findExecuteTask(TaskType.SyncBinary);
Expand Down

0 comments on commit 7106807

Please sign in to comment.