Skip to content
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

wip #43 add next time at to web UI #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Diff view
27 changes: 26 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,32 @@ def self.registered(app)
redirect "#{root_path}recurring"
end
end

##
# Helpers for the the web view
class Helpers
def self.next_run_at(cronline)
t = Fugit.parse_cron(cronline).next_time.send(:to_time) rescue nil
if t
[
time_in_words(t),
time_in_words_to_now(t)
].join(" ")
end
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
4 changes: 4 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,9 @@
<tr>
<td><%= name %></td>
<td><%= job_spec.fetch 'cron', job_spec['every'] %></td>
<td>
<%= @helpers.next_run_at(job_spec.fetch('cron')) %>
</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