refactor: use job_id instead of job_name (#35242)

depends on https://github.com/frappe/frappe/pull/20951
This commit is contained in:
Ankush Menat 2023-05-10 13:26:10 +05:30 committed by GitHub
parent 5d43b35d20
commit 2ea38333f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 13 deletions

View File

@ -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,

View File

@ -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,
)

View File

@ -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,
)

View File

@ -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
)