From f2afceb6e2e495003f643ff05275dca107349ad4 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Sat, 19 Jan 2019 21:51:25 +0530 Subject: [PATCH] feat(recorder): Update request list in realtime --- .../js/frappe/recorder/RecorderDetail.vue | 40 +++++++++---------- frappe/recorder.py | 1 + frappe/www/recorder.py | 3 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/frappe/public/js/frappe/recorder/RecorderDetail.vue b/frappe/public/js/frappe/recorder/RecorderDetail.vue index a694e92142..cda8eebe30 100644 --- a/frappe/public/js/frappe/recorder/RecorderDetail.vue +++ b/frappe/public/js/frappe/recorder/RecorderDetail.vue @@ -4,16 +4,9 @@ Recorder {{ status.status }} - - - - + + - @@ -35,7 +28,7 @@ - + @@ -81,7 +74,8 @@ export default { }; }, mounted() { - this.refresh() + frappe.socketio.init(9000) + this.fetch_status() }, computed: { pages: function() { @@ -103,9 +97,6 @@ export default { } }, methods: { - comment_when(value) { - return comment_when(value) - }, filtered: function(requests) { requests = requests.slice() const filters = Object.entries(this.query.filters) @@ -144,10 +135,7 @@ export default { return "glyphicon-sort" } }, - refresh: function(){ - frappe.call("frappe.www.recorder.get_status").then( r => { - this.status = r.message - }) + refresh: function() { frappe.call("frappe.www.recorder.get_requests").then( r => { this.requests = r.message this.last_fetched = new Date() @@ -159,8 +147,20 @@ export default { args: { should_record: should_record } - }).then(r => this.refresh()) - } + }).then(r => this.update_status(r.message)) + }, + fetch_status: function() { + this.refresh() + frappe.call("frappe.www.recorder.get_status").then(r => this.update_status(r.message)) + }, + update_status: function(status) { + this.status = status + if(this.status.status == "Active") { + frappe.realtime.on("recorder-dump-event", this.refresh) + } else { + frappe.realtime.off("recorder-dump-event", this.refresh) + } + }, }, filters: { elipsize: function (value) { diff --git a/frappe/recorder.py b/frappe/recorder.py index 89f930b180..31e7722a37 100644 --- a/frappe/recorder.py +++ b/frappe/recorder.py @@ -73,6 +73,7 @@ def record(): def dump(): if hasattr(frappe.local, "_recorder"): frappe.local._recorder.dump() + frappe.publish_realtime(event="recorder-dump-event") class Recorder(): diff --git a/frappe/www/recorder.py b/frappe/www/recorder.py index 6c7522df60..3d50d65f42 100644 --- a/frappe/www/recorder.py +++ b/frappe/www/recorder.py @@ -31,12 +31,13 @@ def get_status(): @frappe.whitelist() def set_recorder_state(should_record): - print(should_record) do_not_record() if should_record == "true": frappe.cache().set("recorder-intercept", 1) + return {"status": "Active", "color": "green"} else: frappe.cache().delete("recorder-intercept") + return {"status": "Inactive", "color": "red"} @frappe.whitelist()
{{ request.index }}{{ request.time }} {{ request.method }} {{ request.path | elipsize }} {{ request.cmd | elipsize }}