Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: misc sys health report fixes #26262

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion frappe/core/doctype/comment/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def update_comments_in_parent(reference_doctype, reference_name, _comments):
)

except Exception as e:
if frappe.db.is_column_missing(e) and getattr(frappe.local, "request", None):
if frappe.db.is_missing_column(e) and getattr(frappe.local, "request", None):
pass
elif frappe.db.is_data_too_long(e):
raise frappe.DataTooLongException
Expand Down
25 changes: 23 additions & 2 deletions frappe/desk/doctype/system_health_report/system_health_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,29 @@
import os
from collections import defaultdict
from collections.abc import Callable
from contextlib import contextmanager

import frappe
from frappe.model.document import Document
from frappe.utils.background_jobs import get_queue, get_queue_list
from frappe.utils.background_jobs import get_queue, get_queue_list, get_redis_conn
from frappe.utils.caching import redis_cache
from frappe.utils.data import add_to_date
from frappe.utils.scheduler import get_scheduler_status


@contextmanager
def no_wait(func):
"Disable tenacity waiting on some function"
from tenacity import stop_after_attempt

try:
original_stop = func.retry.stop
func.retry.stop = stop_after_attempt(1)
yield
finally:
func.retry.stop = original_stop


def health_check(step: str):
assert isinstance(step, str), "Invalid usage of decorator, Usage: @health_check('step name')"

Expand All @@ -37,8 +51,11 @@ def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
frappe.log(frappe.get_traceback())
# nosemgrep
frappe.msgprint(f"System Health check step {frappe.bold(step)} failed: {e}", alert=True)
frappe.msgprint(
f"System Health check step {frappe.bold(step)} failed: {e}", alert=True, indicator="red"
)

return wrapper

Expand Down Expand Up @@ -126,7 +143,10 @@ def load_from_db(self):
self.fetch_user_stats()

@health_check("Background Jobs")
@no_wait(get_redis_conn)
def fetch_background_jobs(self):
self.background_jobs_check = "failed"
# This just checks connection life
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")
Expand Down Expand Up @@ -292,6 +312,7 @@ def get_stats(**kwargs):


@frappe.whitelist()
@no_wait(get_redis_conn)
def get_job_status(job_id: str | None = None):
frappe.only_for("System Manager")
try:
Expand Down
4 changes: 2 additions & 2 deletions frappe/desk/doctype/tag/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def check_user_tags(dt):
doctype = DocType(dt)
frappe.qb.from_(doctype).select(doctype._user_tags).limit(1).run()
except Exception as e:
if frappe.db.is_column_missing(e):
if frappe.db.is_missing_column(e):
DocTags(dt).setup()


Expand Down Expand Up @@ -118,7 +118,7 @@ def update(self, dn, tl):
doc = frappe.get_doc(self.dt, dn)
update_tags(doc, tags)
except Exception as e:
if frappe.db.is_column_missing(e):
if frappe.db.is_missing_column(e):
if not tags:
# no tags, nothing to do
return
Expand Down
2 changes: 1 addition & 1 deletion frappe/desk/doctype/todo/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def update_in_reference(self):
# no table
return

elif frappe.db.is_column_missing(e):
elif frappe.db.is_missing_column(e):
from frappe.database.schema import add_column

add_column(self.reference_type, "_assign", "Text")
Expand Down
2 changes: 1 addition & 1 deletion frappe/desk/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _toggle_like(doctype, name, add, user=None):
frappe.db.set_value(doctype, name, "_liked_by", json.dumps(liked_by), update_modified=False)

except frappe.db.ProgrammingError as e:
if frappe.db.is_column_missing(e):
if frappe.db.is_missing_column(e):
add_column(doctype, "_liked_by", "Text")
_toggle_like(doctype, name, add, user)
else:
Expand Down