Skip to content

Commit

Permalink
refactored to move logic from view into helper mattyr#43
Browse files Browse the repository at this point in the history
  • Loading branch information
vanboom committed Oct 5, 2022
1 parent 3c83ef5 commit 4faa67d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/sidecloq/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ def self.registered(app)
##
# Helpers for the the web view
class Helpers
def self.next_run(cronline)
Fugit.parse_cron(cronline).next_time.send(:to_time) rescue nil
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)
Expand Down
7 changes: 1 addition & 6 deletions web/views/recurring.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
<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 %>
<%= @helpers.next_run_at(job_spec.fetch('cron')) %>
</td>
<td><%= job_spec['class'] %></td>
<td>
Expand Down

0 comments on commit 4faa67d

Please sign in to comment.