'use strict'; const SHORT_TASK_QUERY_TIMEOUT_MS = 15000; const SHORT_TASK_EXECUTION_TIMEOUT_MS = 30000; /** * 每 1 分钟在单 worker 中同步一次正常出库订单到配送表。 */ module.exports = { schedule: { interval: '1m', type: 'worker', immediate: false, disable: false, }, queryTimeoutMs: SHORT_TASK_QUERY_TIMEOUT_MS, executionTimeoutMs: SHORT_TASK_EXECUTION_TIMEOUT_MS, /** * 执行已出库订单迁移任务。 * * @param {Object} ctx Egg 上下文。 * @return {Promise} 无返回值。 */ async task(ctx) { if (ctx.app._syncOutboundOrdersToDeliveryRunning) { return; } ctx.app._syncOutboundOrdersToDeliveryRunning = true; try { const result = await ctx.service.systems.orderDeliveryMigration.syncOutboundOrdersToDelivery({ queryTimeoutMs: SHORT_TASK_QUERY_TIMEOUT_MS, executionTimeoutMs: SHORT_TASK_EXECUTION_TIMEOUT_MS, }); if (result && result.retryableFailure) { ctx.logger.warn(`[sync-outbound-orders-to-delivery] 正常迁移遇到 ${result.retryableFailureType},已标记 ${result.timeoutCount || 0} 条订单为出库超时`); } else if (result && result.totalCreated > 0) { ctx.logger.info(`[sync-outbound-orders-to-delivery] 同步 ${result.totalCreated} 条已出库订单`); } } catch (error) { ctx.logger.error(`[sync-outbound-orders-to-delivery] 同步失败: ${error.message}`); } finally { ctx.app._syncOutboundOrdersToDeliveryRunning = false; } }, };