From 8ef10765d68fd336273285dd7b79ee7c92c5d675 Mon Sep 17 00:00:00 2001 From: Joseph Huckaby Date: Thu, 3 Oct 2024 18:08:23 -0700 Subject: [PATCH] Version 0.9.60 - Bring back the live job status column, but show "Last Run" if no active jobs. --- htdocs/js/pages/Schedule.class.js | 54 +++++++++++++++++++++++++++++-- package.json | 2 +- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/htdocs/js/pages/Schedule.class.js b/htdocs/js/pages/Schedule.class.js index 83fea8da..ff8fb9f2 100644 --- a/htdocs/js/pages/Schedule.class.js +++ b/htdocs/js/pages/Schedule.class.js @@ -62,7 +62,7 @@ Class.subclass( Page.Base, "Page.Schedule", { 'Plugin', 'Target', 'Timing', - 'Last Run', + 'Status', 'Actions' ]; @@ -236,6 +236,8 @@ Class.subclass( Page.Base, "Page.Schedule", { $P().set_search_filters(); } } ); + + self.update_live_job_counts(); }, 1 ); }, @@ -243,17 +245,62 @@ Class.subclass( Page.Base, "Page.Schedule", { // update last run state for all jobs, called when state is updated if (!app.state.jobCodes) return; + var event_counts = {}; + + for (var job_id in app.activeJobs) { + var job = app.activeJobs[job_id]; + event_counts[job.event] = (event_counts[job.event] || 0) + 1; + } + for (var event_id in app.state.jobCodes) { - var last_code = app.state.jobCodes[event_id]; - var status_html = last_code ? ' Error' : ' Success'; + if (!(event_id in event_counts)) { + var last_code = app.state.jobCodes[event_id]; + var status_html = last_code ? ' Error' : ' Success'; + this.div.find('#ss_' + event_id).html( status_html ); + } + } + }, + + update_live_job_counts: function() { + // app.activeJobs + var event_counts = {}; + + for (var job_id in app.activeJobs) { + var job = app.activeJobs[job_id]; + event_counts[job.event] = (event_counts[job.event] || 0) + 1; + } + + for (var event_id in event_counts) { + var count = event_counts[event_id]; + var status_html = 'Running (' + count + ')'; this.div.find('#ss_' + event_id).html( status_html ); } + + this.update_job_last_runs(); }, jump_to_last_job: function(idx) { // locate ID of latest completed job for event, and redirect to it var event = this.events[idx]; + var event_counts = {}; + + for (var job_id in app.activeJobs) { + var job = app.activeJobs[job_id]; + event_counts[job.event] = (event_counts[job.event] || 0) + 1; + } + + if (event_counts[event.id]) { + // if event has active jobs, change behavior of click + // if exactly 1 job, link to it -- if more, do nothing + if (event_counts[event.id] == 1) { + var job = find_object( Object.values(app.activeJobs), { event: event.id } ); + if (job) Nav.go( 'JobDetails?id=' + job.id ); + return; + } + else return; + } + // jump to last completed job app.api.post( 'app/get_event_history', { id: event.id, offset: 0, limit: 1 }, function(resp) { if (resp && resp.rows && resp.rows[0]) { var job = resp.rows[0]; @@ -1832,6 +1879,7 @@ Class.subclass( Page.Base, "Page.Schedule", { onStatusUpdate: function(data) { // received status update (websocket) + if (data.jobs_changed) this.update_live_job_counts(); }, onResizeDelay: function(size) { diff --git a/package.json b/package.json index 880cc720..e470af6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Cronicle", - "version": "0.9.59", + "version": "0.9.60", "description": "A simple, distributed task scheduler and runner with a web based UI.", "author": "Joseph Huckaby ", "homepage": "https://github.com/jhuckaby/Cronicle",