Skip to content

Commit

Permalink
Simplify time helpers
Browse files Browse the repository at this point in the history
One of them is basically the same as another one.
  • Loading branch information
rosa committed Dec 2, 2024
1 parent 7311c0e commit 87c7c8b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 19 deletions.
10 changes: 1 addition & 9 deletions app/helpers/mission_control/jobs/dates_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module MissionControl::Jobs::DatesHelper
def time_ago_in_words_with_title(time)
tag.span time_ago_in_words(time), title: time.to_fs(:long)
end

def time_distance_in_words_with_title(time)
tag.span distance_of_time_in_words_to_now(time, include_seconds: true), title: "Since #{time.to_fs(:long)}"
tag.span time_ago_in_words(time, include_seconds: true), title: "Since #{time.to_fs(:long)}"
end

def bidirectional_time_distance_in_words_with_title(time)
Expand All @@ -16,8 +12,4 @@ def bidirectional_time_distance_in_words_with_title(time)

tag.span time_distance, title: time.to_fs(:long)
end

def formatted_time(time)
time.in_time_zone.strftime("%Y-%m-%d %H:%M:%S.%3N %Z")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<tr>
<th>Enqueued</th>
<td>
<%= time_ago_in_words_with_title(job.enqueued_at.to_datetime) %> ago
<%= time_distance_in_words_with_title(job.enqueued_at.to_datetime) %> ago
</td>
</tr>
<% if job.scheduled? %>
Expand All @@ -41,15 +41,15 @@
<tr>
<th>Failed</th>
<td>
<%= time_ago_in_words_with_title(job.failed_at) %> ago
<%= time_distance_in_words_with_title(job.failed_at) %> ago
</td>
</tr>
<% end %>
<% if job.finished_at.present? %>
<tr>
<th>Finished at</th>
<td>
<%= time_ago_in_words_with_title(job.finished_at) %> ago
<%= time_distance_in_words_with_title(job.finished_at) %> ago
</td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/mission_control/jobs/jobs/_job.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="is-family-monospace"><%= job_arguments(job) %></div>
<% end %>

<div class="has-text-grey is-size-7">Enqueued <%= time_ago_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
<div class="has-text-grey is-size-7">Enqueued <%= time_distance_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
</td>

<%= render "mission_control/jobs/jobs/#{jobs_status}/job", job: job %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/mission_control/jobs/jobs/failed/_job.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<td>
<%= link_to failed_job_error(job), application_job_path(@application, job.job_id, anchor: "error") %>
<div class="has-text-grey"><%= time_ago_in_words_with_title(job.failed_at) %> ago</div>
<div class="has-text-grey"><%= time_distance_in_words_with_title(job.failed_at) %> ago</div>
</td>
<td class="pr-0">
<%= render "mission_control/jobs/jobs/failed/actions", job: job %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/mission_control/jobs/jobs/finished/_job.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td>
<td><div class="has-text-grey"><%= formatted_time(job.finished_at) %></div></td>
<td><div class="has-text-grey"><%= time_distance_in_words_with_title(job.finished_at) %> ago</div></td>
2 changes: 1 addition & 1 deletion app/views/mission_control/jobs/queues/_job.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= link_to application_job_path(@application, job.job_id, filter: { queue_name: job.queue }) do %>
<%= job_title(job) %>
<% end %>
<div class="has-text-grey">Enqueued <%= time_ago_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
<div class="has-text-grey">Enqueued <%= time_distance_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
</td>
<td>
<% if job.serialized_arguments.present? %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/mission_control/jobs/shared/_job.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= link_to application_job_path(@application, job.job_id, filter: { queue_name: job.queue }) do %>
<%= job_title(job) %>
<% end %>
<div class="has-text-grey">Enqueued <%= time_ago_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
<div class="has-text-grey">Enqueued <%= time_distance_in_words_with_title(job.enqueued_at.to_datetime) %> ago</div>
</td>
<td>
<% if job.serialized_arguments.present? %>
Expand All @@ -18,7 +18,7 @@
<% if job.started_at %>
Running for <%= time_distance_in_words_with_title(job.started_at) %>
<% elsif job.finished_at %>
Finished <%= time_ago_in_words_with_title(job.finished_at) %> ago
Finished <%= time_distance_in_words_with_title(job.finished_at) %> ago
<% else %>
Pending
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/mission_control/jobs/workers/_worker.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
<% end %>
</td>

<td><div class="has-text-grey"><%= time_ago_in_words_with_title(worker.last_heartbeat_at) %> ago</div></td>
<td><div class="has-text-grey"><%= time_distance_in_words_with_title(worker.last_heartbeat_at) %> ago</div></td>
</tr>

0 comments on commit 87c7c8b

Please sign in to comment.