Browse Source

feat(task): 添加任务交付和号码ID字段,更新任务状态逻辑

xiongzhu 1 year ago
parent
commit
2d58dad4b0
3 changed files with 31 additions and 0 deletions
  1. 8 0
      src/task/entities/task-item.entity.ts
  2. 14 0
      src/task/task.service.ts
  3. 9 0
      src/task/types.d.ts

+ 8 - 0
src/task/entities/task-item.entity.ts

@@ -34,4 +34,12 @@ export class TaskItem {
 
     @Column({ default: false })
     embed: boolean
+
+    @Column({ default: 0 })
+    @Index()
+    delivery: number
+
+    @Column({ nullable: true })
+    @Index()
+    numberId: number
 }

+ 14 - 0
src/task/task.service.ts

@@ -38,6 +38,7 @@ import { BalanceRecord, BalanceType } from '../balance/entities/balance-record.e
 import { Device } from '../device/entities/device.entity'
 import Decimal from 'decimal.js'
 import { CountryConfigService } from '../country-config/country-config.service'
+import { TaskResult } from './types'
 import { dashboard } from '../rcs-number/impl/dashboard.service'
 import { smspva } from '../rcs-number/impl/smspva.service'
 
@@ -1396,6 +1397,19 @@ export class TaskService implements OnModuleInit {
                     if (res.retry?.length > 0) {
                         await this.updateTaskItemStatus(res.retry, TaskItemStatus.IDLE)
                     }
+                    if (res instanceof Array) {
+                        const results = res as TaskResult[]
+                        for (let result of results) {
+                            this.taskItemRepository.update(
+                                { id: result.id },
+                                {
+                                    status: result.sent ? TaskItemStatus.SUCCESS : TaskItemStatus.FAIL,
+                                    delivery: result.delivery,
+                                    numberId: result.numberId
+                                }
+                            )
+                        }
+                    }
                 } catch (e) {
                     Logger.error('Error running task 3', e.stack, this.TAG)
                     await this.updateTaskItemStatus(

+ 9 - 0
src/task/types.d.ts

@@ -1,3 +1,4 @@
+import { Interface } from './../../node_modules/@types/yauzl/node_modules/@types/node/readline.d'
 declare interface TaskConfig {
     checkConnection: boolean
     connectionTimeout: number
@@ -7,3 +8,11 @@ declare interface TaskConfig {
     numberUsage: number
     cleaningInterval: number
 }
+
+declare interface TaskResult {
+    id: number
+    messageId?: string
+    sent: boolean
+    delivery: number
+    numberId: number
+}