From 3c83ef567536f87beff3febe4cb336e34aedc3fc Mon Sep 17 00:00:00 2001 From: Vanboom Date: Wed, 5 Oct 2022 11:35:41 -0500 Subject: [PATCH] wip #43 add next time at to web UI --- lib/sidecloq/web.rb | 21 ++++++++++++++++++++- web/views/recurring.erb | 9 +++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/sidecloq/web.rb b/lib/sidecloq/web.rb index 7481751..75b95c8 100644 --- a/lib/sidecloq/web.rb +++ b/lib/sidecloq/web.rb @@ -6,7 +6,7 @@ module Web def self.registered(app) app.get '/recurring' do @schedule = Schedule.from_redis - + @helpers = Sidecloq::Web::Helpers erb File.read(File.join(VIEW_PATH, 'recurring.erb')) end @@ -21,7 +21,26 @@ def self.registered(app) redirect "#{root_path}recurring" end end + + ## + # Helpers for the the web view + class Helpers + def self.next_run(cronline) + Fugit.parse_cron(cronline).next_time.send(:to_time) rescue nil + end + def self.time_in_words(t) + return unless t.is_a?(Time) + t.strftime("%D %R") + end + def self.time_in_words_to_now(t) + return unless t.is_a?(Time) + hrs = (t - Time.now) / 1.hour + min = hrs.modulo(1) * 60 + "#{hrs.truncate} hrs #{min.ceil} min" + end + end end + end Sidekiq::Web.register(Sidecloq::Web) diff --git a/web/views/recurring.erb b/web/views/recurring.erb index c34ca8a..c530c20 100644 --- a/web/views/recurring.erb +++ b/web/views/recurring.erb @@ -6,6 +6,7 @@ Name Cron + Next Run Class Queue Arguments @@ -18,6 +19,14 @@ <%= name %> <%= job_spec.fetch 'cron', job_spec['every'] %> + + <% t = @helpers.next_run(job_spec.fetch 'cron') %> + <% if t %> + <%= @helpers.time_in_words_to_now(t.send(:to_time)) %> + @ + <%= @helpers.time_in_words(t) %> + <% end %> + <%= job_spec['class'] %> <%= job_spec.fetch('queue', 'default') %>