From 2ea38333f0b9b9d01b094203d86216dc22c5c942 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 10 May 2023 13:26:10 +0530 Subject: [PATCH] refactor: use `job_id` instead of `job_name` (#35242) depends on https://github.com/frappe/frappe/pull/20951 --- .../bank_statement_import/bank_statement_import.py | 7 ++++--- erpnext/accounts/doctype/ledger_merge/ledger_merge.py | 7 ++++--- .../opening_invoice_creation_tool.py | 8 +++++--- .../pos_invoice_merge_log/pos_invoice_merge_log.py | 8 ++++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py index d8880f70417..003a43c5c2c 100644 --- a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py +++ b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py @@ -53,19 +53,20 @@ class BankStatementImport(DataImport): if "Bank Account" not in json.dumps(preview["columns"]): frappe.throw(_("Please add the Bank Account column")) - from frappe.utils.background_jobs import is_job_queued + from frappe.utils.background_jobs import is_job_enqueued from frappe.utils.scheduler import is_scheduler_inactive if is_scheduler_inactive() and not frappe.flags.in_test: frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive")) - if not is_job_queued(self.name): + job_id = f"bank_statement_import::{self.name}" + if not is_job_enqueued(job_id): enqueue( start_import, queue="default", timeout=6000, event="data_import", - job_name=self.name, + job_id=job_id, data_import=self.name, bank_account=self.bank_account, import_file_path=self.import_file, diff --git a/erpnext/accounts/doctype/ledger_merge/ledger_merge.py b/erpnext/accounts/doctype/ledger_merge/ledger_merge.py index 7cd6d04c35c..381083bc304 100644 --- a/erpnext/accounts/doctype/ledger_merge/ledger_merge.py +++ b/erpnext/accounts/doctype/ledger_merge/ledger_merge.py @@ -4,7 +4,7 @@ import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils.background_jobs import is_job_queued +from frappe.utils.background_jobs import is_job_enqueued from erpnext.accounts.doctype.account.account import merge_account @@ -17,13 +17,14 @@ class LedgerMerge(Document): if is_scheduler_inactive() and not frappe.flags.in_test: frappe.throw(_("Scheduler is inactive. Cannot merge accounts."), title=_("Scheduler Inactive")) - if not is_job_queued(self.name): + job_id = f"ledger_merge::{self.name}" + if not is_job_enqueued(job_id): enqueue( start_merge, queue="default", timeout=6000, event="ledger_merge", - job_name=self.name, + job_id=job_id, docname=self.name, now=frappe.conf.developer_mode or frappe.flags.in_test, ) diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py index 47c2ceb6e49..680afb1143b 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py @@ -6,7 +6,7 @@ import frappe from frappe import _, scrub from frappe.model.document import Document from frappe.utils import flt, nowdate -from frappe.utils.background_jobs import enqueue, is_job_queued +from frappe.utils.background_jobs import enqueue, is_job_enqueued from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( get_accounting_dimensions, @@ -212,13 +212,15 @@ class OpeningInvoiceCreationTool(Document): if is_scheduler_inactive() and not frappe.flags.in_test: frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive")) - if not is_job_queued(self.name): + job_id = f"opening_invoice::{self.name}" + + if not is_job_enqueued(job_id): enqueue( start_import, queue="default", timeout=6000, event="opening_invoice_creation", - job_name=self.name, + job_id=job_id, invoices=invoices, now=frappe.conf.developer_mode or frappe.flags.in_test, ) diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index b1e22087dbd..d8aed219e24 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -9,7 +9,7 @@ from frappe import _ from frappe.model.document import Document from frappe.model.mapper import map_child_doc, map_doc from frappe.utils import cint, flt, get_time, getdate, nowdate, nowtime -from frappe.utils.background_jobs import enqueue, is_job_queued +from frappe.utils.background_jobs import enqueue, is_job_enqueued from frappe.utils.scheduler import is_scheduler_inactive @@ -483,15 +483,15 @@ def enqueue_job(job, **kwargs): closing_entry = kwargs.get("closing_entry") or {} - job_name = closing_entry.get("name") - if not is_job_queued(job_name): + job_id = "pos_invoice_merge::" + str(closing_entry.get("name")) + if not is_job_enqueued(job_id): enqueue( job, **kwargs, queue="long", timeout=10000, event="processing_merge_logs", - job_name=job_name, + job_id=job_id, now=frappe.conf.developer_mode or frappe.flags.in_test )