8000 fix: avoid flushing to monitor logs concurrently (backport #32552) by mergify[bot] · Pull Request #32555 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: avoid flushing to monitor logs concurrently (backport #32552) #32555

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

Merged
merged 1 commit into from
May 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
25 changes: 13 additions & 12 deletions frappe/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import frappe
from frappe.utils.data import cint
from frappe.utils.synchronization import filelock

MONITOR_REDIS_KEY = "monitor-transactions"
MONITOR_MAX_ENTRIES = 1000000
Expand Down Expand Up @@ -123,15 +124,15 @@ def store(self):


def flush():
try:
# Fetch all the logs without removing from cache
logs = frappe.cache.lrange(MONITOR_REDIS_KEY, 0, -1)
if logs:
logs = list(map(frappe.safe_decode, logs))
with open(log_file(), "a") as f:
f.write("\n".join(logs))
f.write("\n")
# Remove fetched entries from cache
frappe.cache.ltrim(MONITOR_REDIS_KEY, len(logs) - 1, -1)
except Exception:
traceback.print_exc()
logs = frappe.cache.lrange(MONITOR_REDIS_KEY, 0, -1)
if not logs:
return

logs = list(map(frappe.safe_decode, logs))
with filelock("monitor_flush", is_global=True, timeout=5):
with open(log_file(), "a") as f:
f.write("\n".join(logs))
f.write("\n")

# Remove fetched entries from cache
frappe.cache.ltrim(MONITOR_REDIS_KEY, len(logs) - 1, -1)
0