refactor: exception propogation

(cherry picked from commit 4a55240e63)
This commit is contained in:
ruthra kumar
2024-03-19 17:39:20 +05:30
committed by Mergify
parent 3f45f63ff8
commit 02c3303fee
2 changed files with 20 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
"column_break_txbg",
"status",
"tasks_section",
"error_log",
"delete_bin_data",
"delete_leads_and_addresses",
"reset_company_default_values",
@@ -122,12 +123,18 @@
"label": "Initialize Summary Table",
"no_copy": 1,
"read_only": 1
},
{
"depends_on": "eval: doc.error_log",
"fieldname": "error_log",
"fieldtype": "Long Text",
"label": "Error Log"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-02-05 10:36:34.229864",
"modified": "2024-03-19 17:04:49.369734",
"modified_by": "Administrator",
"module": "Setup",
"name": "Transaction Deletion Record",

View File

@@ -35,6 +35,7 @@ class TransactionDeletionRecord(Document):
delete_transactions: DF.Check
doctypes: DF.Table[TransactionDeletionRecordDetails]
doctypes_to_be_ignored: DF.Table[TransactionDeletionRecordItem]
error_log: DF.LongText | None
initialize_doctypes_table: DF.Check
reset_company_default_values: DF.Check
status: DF.Literal["Queued", "Running", "Failed", "Completed", "Cancelled"]
@@ -146,11 +147,21 @@ class TransactionDeletionRecord(Document):
task_to_execute=task,
)
# todo: add a non-background job based approach as well
def execute_task(self, task_to_execute: str | None = None):
if task_to_execute:
method = self.task_to_internal_method_map[task_to_execute]
if task := getattr(self, method, None):
task()
try:
task()
except Exception as err:
frappe.db.rollback()
traceback = frappe.get_traceback(with_context=True)
if traceback:
message = "Traceback: <br>" + traceback
frappe.db.set_value(self.doctype, self.name, "error_log", message)
frappe.db.set_value(self.doctype, self.name, "status", "Failed")
def delete_notifications(self):
self.validate_doc_status()