From 196cfbeb0cec610acf3a12c79b48a6b216856854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 30 Mar 2024 12:03:30 +0100 Subject: [PATCH] Do the marketing record activity in the queue This avoid to block the cron for a long period if there is a lot of record activities to process. In case of failure the record activities will be retried. And in case of long delay in the queue, the record activities will not be processed twice thanks to the transition filter of the workflow and the lock when updating state field. Closes #13146 --- modules/marketing_automation/marketing_automation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/marketing_automation/marketing_automation.py b/modules/marketing_automation/marketing_automation.py index 194ebc92f2..7d81c7377c 100644 --- a/modules/marketing_automation/marketing_automation.py +++ b/modules/marketing_automation/marketing_automation.py @@ -982,13 +982,17 @@ class RecordActivity(Workflow, ModelSQL, ModelView): @classmethod def process(cls): + transaction = Transaction() + context = transaction.context now = datetime.datetime.now() activities = cls.search([ ('state', '=', 'waiting'), ('at', '<=', now), ('record.blocked', '!=', True), ]) - cls.do(activities) + with transaction.set_context( + queue_batch=context.get('queue_batch', True)): + cls.__queue__.do(activities) @classmethod @ModelView.button