27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
"""电商渠道调度任务 actors(Dramatiq)。"""
|
||
|
||
import dramatiq
|
||
|
||
from .models import ChannelAccount
|
||
from . import services as channel_services
|
||
|
||
|
||
@dramatiq.actor(max_retries=3, time_limit=600_000)
|
||
def sync_orders_for_account(account_id: int):
|
||
"""单店铺拉单转单(仅处理已配置凭证的店铺)。"""
|
||
account = ChannelAccount.objects.get(pk=account_id, is_active=True)
|
||
return channel_services.sync_channel_orders(account, auto_convert=True)
|
||
|
||
|
||
@dramatiq.actor(max_retries=3, time_limit=900_000)
|
||
def sync_orders_for_all_active_accounts():
|
||
"""遍历全部启用且已配置凭证的店铺自动拉单(crontab 每日 02:00 触发)。"""
|
||
summary = []
|
||
for account in ChannelAccount.objects.filter(is_active=True).exclude(app_key=""):
|
||
try:
|
||
result = channel_services.sync_channel_orders(account, auto_convert=True)
|
||
summary.append({"shop_id": account.shop_id, **result})
|
||
except Exception as e:
|
||
summary.append({"shop_id": account.shop_id, "error": str(e)})
|
||
return summary
|