fix: Set prepared report even if req times out (#29874)
This commit is contained in:
parent
bebc40087c
commit
8071d38ad2
1 changed files with 15 additions and 4 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
# License: MIT. See LICENSE
|
# License: MIT. See LICENSE
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
import threading
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import frappe.desk.query_report
|
import frappe.desk.query_report
|
||||||
|
|
@ -160,6 +161,14 @@ class Report(Document):
|
||||||
threshold = 15
|
threshold = 15
|
||||||
|
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
|
prepared_report_watcher = None
|
||||||
|
if not self.prepared_report:
|
||||||
|
prepared_report_watcher = threading.Timer(
|
||||||
|
interval=threshold,
|
||||||
|
function=enable_prepared_report,
|
||||||
|
kwargs={"report": self.name, "site": frappe.local.site},
|
||||||
|
)
|
||||||
|
prepared_report_watcher.start()
|
||||||
|
|
||||||
# The JOB
|
# The JOB
|
||||||
if self.is_standard == "Yes":
|
if self.is_standard == "Yes":
|
||||||
|
|
@ -167,10 +176,8 @@ class Report(Document):
|
||||||
else:
|
else:
|
||||||
res = self.execute_script(filters)
|
res = self.execute_script(filters)
|
||||||
|
|
||||||
# automatically set as prepared
|
prepared_report_watcher and prepared_report_watcher.cancel()
|
||||||
execution_time = (datetime.datetime.now() - start_time).total_seconds()
|
execution_time = (datetime.datetime.now() - start_time).total_seconds()
|
||||||
if execution_time > threshold and not self.prepared_report and not frappe.conf.developer_mode:
|
|
||||||
frappe.enqueue(enable_prepared_report, report=self.name)
|
|
||||||
|
|
||||||
frappe.cache.hset("report_execution_time", self.name, execution_time)
|
frappe.cache.hset("report_execution_time", self.name, execution_time)
|
||||||
|
|
||||||
|
|
@ -418,5 +425,9 @@ def get_group_by_column_label(args, meta):
|
||||||
return label
|
return label
|
||||||
|
|
||||||
|
|
||||||
def enable_prepared_report(report: str):
|
def enable_prepared_report(report: str, site: str):
|
||||||
|
frappe.init(site)
|
||||||
|
frappe.connect()
|
||||||
frappe.db.set_value("Report", report, "prepared_report", 1)
|
frappe.db.set_value("Report", report, "prepared_report", 1)
|
||||||
|
frappe.db.commit()
|
||||||
|
frappe.destroy()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue