Stop a running exchange: - SyncRun gets a Celery task_id and a "stopped" status - The task is bound and passes its id into the run, so the admin can revoke it with app.control.revoke(..., terminate=True) - Admin action "Stop synchronization" reports stopped, already finished, runs without a task id and broker errors separately - A stopped run is never overwritten by the task result Alerts about exchange failures: - NotificationSettings singleton (admin section): on/off, email recipients, Telegram bot token and chat id, per-event flags - notifications.py sends through email and Telegram, best effort: delivery errors are logged and never break the exchange - Fired on catalog apply failure (pull from 1C and inbound push) and on outbox messages that exhausted retries - Admin action "Send test notification" verifies the channels - SMTP settings added to base.py and .env.example so email really works in production; SMS is not implemented (no SMS gateway in the project) Tests: 11 new cases (email/Telegram delivery, flags, outbox dead-letter, stop semantics); the suite is 33 passing.
33 lines
773 B
Python
33 lines
773 B
Python
from celery import shared_task
|
|
|
|
from apps.orders.models import Order
|
|
|
|
from .services import (
|
|
process_outbox as _process_outbox,
|
|
pull_catalog_from_1c,
|
|
pull_order_statuses as _pull_order_statuses,
|
|
push_order_to_1c,
|
|
)
|
|
|
|
|
|
@shared_task(bind=True)
|
|
def sync_catalog_from_1c(self, since=None):
|
|
"""Pulls the catalog from 1C. Bound so the run keeps the Celery task id."""
|
|
return pull_catalog_from_1c(since=since, task_id=self.request.id or "")
|
|
|
|
|
|
@shared_task
|
|
def push_order(order_id):
|
|
order = Order.objects.get(pk=order_id)
|
|
return push_order_to_1c(order)
|
|
|
|
|
|
@shared_task
|
|
def process_outbox(limit: int = 100):
|
|
return _process_outbox(limit=limit)
|
|
|
|
|
|
@shared_task
|
|
def pull_order_statuses(limit: int = 100):
|
|
return _pull_order_statuses(limit=limit)
|