From 09bc9994e1e26caf0321d96bbce7835d92b639d6 Mon Sep 17 00:00:00 2001 From: fproldan Date: Mon, 9 Mar 2026 17:21:52 +0000 Subject: [PATCH 1/2] feat: process batch --- .../doctype/subscription/subscription.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 62555b4e0cb2..93d0e6f72ba6 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -713,11 +713,26 @@ def get_prorata_factor(period_end, period_start, is_prepaid): def process_all(): """ - Task to updates the status of all `Subscription` apart from those that are cancelled + Task to updates the status of all `Subscription` apart from those that are cancelled. + Subscriptions are split into batches and each batch is enqueued as a separate background job. """ + from frappe.utils import create_batch subscriptions = get_all_subscriptions() - for subscription in subscriptions: - process(subscription) + for subscription in create_batch(subscriptions, 200): + frappe.enqueue( + 'erpnext.accounts.doctype.subscription.subscription.process_batch', + batch=subscription, + queue='long', + enqueue_after_commit=True, + ) + + +def process_batch(batch): + """ + Process a batch of subscriptions sequentially. + """ + for data in batch: + process(data) def get_all_subscriptions(): From 628d0415a01b4f1f198bf121d7a3c3a22f58aa0c Mon Sep 17 00:00:00 2001 From: fproldan Date: Mon, 9 Mar 2026 17:23:46 +0000 Subject: [PATCH 2/2] fix --- erpnext/accounts/doctype/subscription/subscription.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 93d0e6f72ba6..82d3c9a8ae63 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -723,7 +723,6 @@ def process_all(): 'erpnext.accounts.doctype.subscription.subscription.process_batch', batch=subscription, queue='long', - enqueue_after_commit=True, )