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
This commit is contained in:
Cédric Krier
2024-03-30 12:03:30 +01:00
parent 5035063b35
commit 196cfbeb0c
@@ -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