fix: checking and unlocking the correct doc

This commit is contained in:
Aradhya 2022-10-08 04:47:37 +05:30
parent 1000a10c24
commit d8ff47aac2
5 changed files with 30 additions and 15 deletions

View file

@ -1,10 +1,12 @@
// Copyright (c) 2022, Frappe Technologies and contributors
// For license information, please see license.txt
frappe.ui.form.on('Submission Queue', {
refresh: function(frm) {
frm.add_custom_button(__("Unlock"), () => {
frm.call("unlock_doc")
})
}
frappe.ui.form.on("Submission Queue", {
refresh: function (frm) {
if (frm.doc.status === "Queued") {
frm.add_custom_button(__("Unlock Reference Document"), () => {
frm.call("unlock_doc");
});
}
},
});

View file

@ -85,7 +85,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-10-06 18:21:01.129702",
"modified": "2022-10-08 04:26:01.657818",
"modified_by": "Administrator",
"module": "Core",
"name": "Submission Queue",
@ -116,6 +116,14 @@
{
"color": "Green",
"title": "Completed"
},
{
"color": "Yellow",
"title": "Stopped"
},
{
"color": "Red",
"title": "Canceled"
}
]
}

View file

@ -1,13 +1,14 @@
# Copyright (c) 2022, Frappe Technologies and contributors
# For license information, please see license.txt
from rq.exceptions import NoSuchJobError
from rq.job import Job
import frappe
from frappe import _
from frappe.desk.doctype.notification_log.notification_log import enqueue_create_notification
from frappe.model.document import Document
from frappe.utils import now
from rq.exceptions import NoSuchJobError
from rq.job import Job
from frappe.utils.background_jobs import get_redis_conn
@ -84,19 +85,24 @@ class SubmissionQueue(Document):
@frappe.whitelist()
def unlock_doc(self):
if self.is_locked:
to_be_unlocked_doc = frappe.get_doc(self.ref_doctype, self.ref_docname)
if to_be_unlocked_doc.is_locked:
try:
job = Job(self.job_id, connection=get_redis_conn())
if not job.get_status(refresh=True):
status = job.get_status(refresh=True)
if not status:
raise NoSuchJobError
if status := status in ("failed", "canceled", "stopped"):
to_be_unlocked_doc.unlock()
self.status = status.capitalize()
self.save()
except NoSuchJobError:
self.to_be_queued_doc.unlock()
to_be_unlocked_doc.unlock()
frappe.msgprint(_("Unlocked document as no such document exists in queue"))
else:
frappe.msgprint(_("Document is already unlocked"))
def queue_submission(doc: Document, action: str):
queue = frappe.new_doc("Submission Queue")
queue.state = "Queued"

View file

@ -22,7 +22,6 @@ def savedocs(doc, action):
if action == "Submit" and doc.meta.queue_in_background and not is_scheduler_inactive():
queue_submission(doc, action)
return
doc.submit()
else:
doc.save()

View file

@ -1498,9 +1498,9 @@ class Document(BaseDocument):
def unlock(self):
"""Delete the lock file for this document"""
file_lock.delete_lock(self.get_signature())
self.is_locked = False
if self in frappe.local.locked_documents:
frappe.local.locked_documents.remove(self)
self.is_locked = False
# validation helpers
def validate_from_to_dates(self, from_date_field, to_date_field):