oms/backend/app/schedule/externalSendSyncWorker.js
liufumingren e1e3bb638f feat(order): 拉单任务、外部发货同步与取号记录
- 拉单任务:新增 order_sync_tasks 异步任务池,按店铺逐店拉取外部打单平台订单,前端轮询进度
- 外部发货同步:配送后把发货结果同步回店管家,提供数量统计与批量重试(externalSendSync)
- 取号:新增 waybill_fetch_records 记录取号过程,外部快递接口补充菜鸟授权信息
- 补齐相关迁移、订单页同步入口/状态展示,并新增对接说明文档

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-04 20:53:35 +08:00

36 lines
975 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 同步外部打单平台发货:每 2 分钟扫描一次「待同步 / 失败待重试」的配送单。
*
* 失败逐单累计次数,达到上限(3 次)转「异常」等人工批量重试;
* 用模块级 running 标记避免同进程叠加执行(单批最多 50 单,平台调用是网络请求)。
*/
let running = false;
module.exports = {
schedule: {
cron: '0 */2 * * * *',
type: 'worker',
disable: false,
},
/**
* 执行一轮
* @param {Egg.Context} ctx egg context
* @return {Promise<void>} 无返回值
*/
async task(ctx) {
if (running) return;
running = true;
try {
const result = await ctx.service.externalSendSync.syncPending({ limit: 50 });
if (result.total) ctx.logger.info('[external-send] 本轮同步结果 %j', result);
} catch (err) {
ctx.logger.error('[external-send] 调度执行失败', err);
} finally {
running = false;
}
},
};