Skip to content

Commit

Permalink
Use server time zone when displaying last run
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanovv committed Feb 13, 2020
1 parent 5f9bcf5 commit c1bfea1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/controllers/clockwork_web/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class HomeController < ActionController::Base
layout false
helper ClockworkWeb::HomeHelper

http_basic_authenticate_with name: ENV["CLOCKWORK_USERNAME"], password: ENV["CLOCKWORK_PASSWORD"] if ENV["CLOCKWORK_PASSWORD"]
http_basic_authenticate_with name: ENV['CLOCKWORK_USERNAME'], password: ENV['CLOCKWORK_PASSWORD'] if ENV['CLOCKWORK_PASSWORD']

def index
@events =
Expand All @@ -19,12 +19,12 @@ def index

@last_runs = ClockworkWeb.last_runs
@disabled = ClockworkWeb.disabled_jobs
@last_heartbeat = ClockworkWeb.last_heartbeat
@last_heartbeat = ClockworkWeb.last_heartbeat.in_time_zone
end

def job
job = params[:job]
enable = params[:enable] == "true"
enable = params[:enable] == 'true'
if enable
ClockworkWeb.enable(job)
else
Expand Down
14 changes: 4 additions & 10 deletions app/helpers/clockwork_web/home_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module HomeHelper

def friendly_period(period)
if period % 1.day == 0
pluralize(period / 1.day, "day")
pluralize(period / 1.day, 'day')
elsif period % 1.hour == 0
pluralize(period / 1.hour, "hour")
pluralize(period / 1.hour, 'hour')
elsif period % 1.minute == 0
"#{period / 1.minute} min"
else
Expand All @@ -14,17 +14,11 @@ def friendly_period(period)
end

def last_run(time)
if time
time_ago_in_words(time)
end
time && time_ago_in_words(time.in_time_zone)
end

def friendly_time_part(time_part)
if time_part
time_part.to_s.rjust(2, "0")
else
"**"
end
time_part ? time_part.to_s.rjust(2, '0') : '**'
end

end
Expand Down
4 changes: 2 additions & 2 deletions app/views/clockwork_web/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<tbody>
<% @events.each do |event| %>
<% enabled = !@disabled.include?(event.job) %>
<tr class="<%= enabled ? "" : "disabled" %>">
<tr class="<%= enabled ? '' : 'disabled' %>">
<td><%= event.job %></td>
<td>
<%= friendly_period(event.instance_variable_get(:@period)) %>
Expand All @@ -95,7 +95,7 @@
<% end %>
</td>
<td><%= last_run(@last_runs[event.job]) %></td>
<td><%= button_to enabled ? "Disable" : "Enable", home_job_path(job: event.job, enable: !enabled), disabled: !ClockworkWeb.redis %></td>
<td><%= button_to enabled ? 'Disable' : 'Enable', home_job_path(job: event.job, enable: !enabled), disabled: !ClockworkWeb.redis %></td>
</tr>
<% end %>
</tbody>
Expand Down

0 comments on commit c1bfea1

Please sign in to comment.