Skip to content

Commit

Permalink
feat: background jobs test
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 22, 2024
1 parent 99d2dea commit 7411c4f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
17 changes: 17 additions & 0 deletions frappe/desk/doctype/system_health_report/system_health_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@
// For license information, please see license.txt

frappe.ui.form.on("System Health Report", {
onload(frm) {
let poll_attempts = 0;
const interval = setInterval(() => {
frappe
.xcall(
"frappe.desk.doctype.system_health_report.system_health_report.get_job_status",
{ job_id: frm.doc.test_job_id }
)
.then((status) => {
poll_attempts += 1;
if (["finished", "failed"].includes(status) || poll_attempts > 30) {
clearInterval(interval);
}
status && frm.set_value("background_jobs_check", status);
});
}, 1000);
},
refresh(frm) {
frm.set_value("socketio_ping_check", "Fail");
frappe.realtime.on("pong", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"scheduler_status",
"column_break_klex",
"total_background_workers",
"column_break_mney",
"background_jobs_check",
"test_job_id",
"section_break_djoz",
"queue_status",
"column_break_wjoz",
Expand Down Expand Up @@ -330,14 +333,29 @@
"fieldname": "realtime_socketio_section",
"fieldtype": "Section Break",
"label": "Realtime (SocketIO)"
},
{
"fieldname": "column_break_mney",
"fieldtype": "Column Break"
},
{
"fieldname": "background_jobs_check",
"fieldtype": "Data",
"label": "Background Jobs Check"
},
{
"fieldname": "test_job_id",
"fieldtype": "Data",
"hidden": 1,
"label": "Test Job ID"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"is_virtual": 1,
"issingle": 1,
"links": [],
"modified": "2024-04-19 14:04:05.484592",
"modified": "2024-04-19 14:12:44.949141",
"modified_by": "Administrator",
"module": "Desk",
"name": "System Health Report",
Expand Down
13 changes: 13 additions & 0 deletions frappe/desk/doctype/system_health_report/system_health_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SystemHealthReport(Document):
from frappe.types import DF

active_sessions: DF.Int
background_jobs_check: DF.Data | None
background_workers: DF.Table[SystemHealthWorkers]
backups_size: DF.Float
binary_logging: DF.Data | None
Expand All @@ -64,6 +65,7 @@ class SystemHealthReport(Document):
scheduler_status: DF.Data | None
socketio_ping_check: DF.Literal["Fail", "Pass"]
socketio_transport_mode: DF.Literal["Polling", "Websocket"]
test_job_id: DF.Data | None
top_db_tables: DF.Table[SystemHealthDBTable]
top_errors: DF.Code | None
total_background_workers: DF.Int
Expand All @@ -87,6 +89,8 @@ def load_from_db(self):
self.fetch_user_stats()

def fetch_background_workers(self):
self.test_job_id = frappe.enqueue("frappe.ping", at_front=True).id
self.background_jobs_check = "queued"
self.scheduler_status = get_scheduler_status().get("status")
workers = frappe.get_all("RQ Worker")
self.total_background_workers = len(workers)
Expand Down Expand Up @@ -232,3 +236,12 @@ def get_count(filters=None, **kwargs):
@staticmethod
def get_stats(**kwargs):
raise NotImplementedError


@frappe.whitelist()
def get_job_status(job_id: str):
frappe.only_for("System Manager")
try:
return frappe.get_doc("RQ Job", job_id).status
except Exception:
frappe.clear_messages()

0 comments on commit 7411c4f

Please sign in to comment.