Преглед изворни кода

Merge remote-tracking branch 'origin/main'

wuyi пре 1 година
родитељ
комит
f6475a90ab
2 измењених фајлова са 21 додато и 6 уклоњено
  1. 9 0
      src/device/device.service.ts
  2. 12 6
      src/task/task.service.ts

+ 9 - 0
src/device/device.service.ts

@@ -143,4 +143,13 @@ export class DeviceService {
             await this.deviceRepository.update(id, { clashProfile: profiles[0] })
         }
     }
+
+    async updateDevices(
+        ids: string[],
+        data: {
+            busy?: boolean
+        }
+    ) {
+        await this.deviceRepository.update(ids, data)
+    }
 }

+ 12 - 6
src/task/task.service.ts

@@ -572,8 +572,7 @@ export class TaskService implements OnModuleInit {
             if (durianRes.data.code === 200) {
                 res.durian = durianRes.data.data.score
             }
-        } catch (e) {
-        }
+        } catch (e) {}
 
         try {
             const cloudInstance = axios.create({
@@ -847,6 +846,8 @@ export class TaskService implements OnModuleInit {
         taskItems.forEach((item) => {
             item.message = this.getMessage(task)
         })
+
+        devices = devices.splice(0, Math.ceil(taskItems.length / 5))
         const taskConfig = {
             rcsWait: task.rcsWait || (await this.getConfig('rcs_wait', 2000)),
             rcsInterval: task.rcsInterval || (await this.getConfig('rcs_interval', 3000)),
@@ -855,13 +856,18 @@ export class TaskService implements OnModuleInit {
             checkConnection: task.checkConnection,
             useBackup: task.useBackup
         }
+
+        await this.updateTaskItemStatusAndSendAt(
+            taskItems.map((i) => i.id),
+            TaskItemStatus.PENDING
+        )
+        await this.deviceService.updateDevices(
+            devices.map((d) => d.id),
+            { busy: true }
+        )
         Promise.all(
             devices.map(async (device, i) => {
                 const items = taskItems.slice(i * 5, i * 5 + 5)
-                await this.updateTaskItemStatusAndSendAt(
-                    items.map((i) => i.id),
-                    TaskItemStatus.PENDING
-                )
                 try {
                     const res: any = await Promise.race([
                         this.eventsGateway.sendForResult(