Skip to content

Commit

Permalink
wip mattyr#43 add next time at to web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
vanboom committed Oct 5, 2022
1 parent d2e664a commit 3c83ef5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/sidecloq/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions web/views/recurring.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<tr>
<th>Name</th>
<th>Cron</th>
<th>Next Run</th>
<th>Class</th>
<th>Queue</th>
<th>Arguments</th>
Expand All @@ -18,6 +19,14 @@
<tr>
<td><%= name %></td>
<td><%= job_spec.fetch 'cron', job_spec['every'] %></td>
<td>
<% 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 %>
</td>
<td><%= job_spec['class'] %></td>
<td>
<a href="<%= root_path %>queues/<%= job_spec.fetch('queue', 'default') %>"><%= job_spec.fetch('queue', 'default') %></a>
Expand Down

0 comments on commit 3c83ef5

Please sign in to comment.