Forráskód Böngészése

Refactor code to sort pending tasks randomly before processing

x1ongzhu 1 éve
szülő
commit
3c4334f897
1 módosított fájl, 2 hozzáadás és 1 törlés
  1. 2 1
      src/task/task.service.ts

+ 2 - 1
src/task/task.service.ts

@@ -898,7 +898,7 @@ export class TaskService implements OnModuleInit {
                     const maxParallel = await this.getConfig('max_parallel', 1)
                     const batchSize = 200
 
-                    const tasks = await this.taskRepository.find({
+                    let tasks = await this.taskRepository.find({
                         where: {
                             status: TaskStatus.PENDING
                         },
@@ -960,6 +960,7 @@ export class TaskService implements OnModuleInit {
                         tasks.push(...cuttingTasks)
                     }
                     if (tasks.length === 0) return
+                    tasks = tasks.sort((a, b) => Math.random() - Math.random())
                     const devices = await this.deviceService.findAllAvailableDevices()
                     if (devices.length === 0) return
                     const countryMapping: { [key: string]: string[] } = JSON.parse(