que-view 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b7b44890b63b063c130537e5fcc117f40bf1236dd89b156ca48e87a78d71248
4
- data.tar.gz: 629fd230eb265fdbe7a41f0aec19e37f4047d797750eb635612687cceb7d5af9
3
+ metadata.gz: 062e48206fe33c45a7f007d831b31a5c4566d6eb4af6891cfad6949108f45b56
4
+ data.tar.gz: c3c2fd233567554fc46e7296a9895d7e8c7b650789fcb1fb7f49d2d023cc3670
5
5
  SHA512:
6
- metadata.gz: 1412a8a378aaa977fd92b40c79dad153267cbf50d1e7ac7409380469106269e5b96484d12193ac57ee78187ad172e79a61783e54e0948aff9242e4947bf6d381
7
- data.tar.gz: ac32754839e4105584d330cc34a19cb5fccb48f8ce60afd58c1c3f5bb9b933a7ab4bd8616e109d7a2a5b91b384dff878b4a5699ee576f5d5fa1822c60d4392b0
6
+ metadata.gz: 3a4b0f0e2bac21033c9e3db5a8ea193b599679e88abb064f7a07b71608893e861e192196d2b688f70c8f9cf5c092d48b40925bfa190d1760172965ac8c319149
7
+ data.tar.gz: 3db157d3fb95fa530c43607ac9c7924b9ca84cbc305f134ae08635048d77c0213e71401770e4e8c30bbffbfc414c4f233d17bd5896ce2b661b12d464f1914c93
@@ -4,6 +4,7 @@ module Que
4
4
  module View
5
5
  class QueueMetricsController < Que::View::ApplicationController
6
6
  before_action :find_queue_metrics, only: %i[index]
7
+ before_action :find_queue_latencies, only: %i[index]
7
8
 
8
9
  def index; end
9
10
 
@@ -12,6 +13,14 @@ module Que
12
13
  def find_queue_metrics
13
14
  @queue_metrics = ::Que::View.fetch_queue_metrics
14
15
  end
16
+
17
+ def find_queue_latencies
18
+ current_time = DateTime.now.to_i
19
+ @queue_latencies =
20
+ ::Que::View
21
+ .fetch_queue_latencies(@queue_metrics.keys)
22
+ .transform_values { |value| current_time - value.to_time.to_i }
23
+ end
15
24
  end
16
25
  end
17
26
  end
@@ -7,7 +7,7 @@
7
7
  <%= form.submit 'Search', class: 'btn-primary' %>
8
8
  </div>
9
9
  <% end %>
10
- <% if @pagination %>
10
+ <% if @pagination && @pagination.total_pages > 1 %>
11
11
  <div class="row pagination">
12
12
  <% if @pagination.previous_page? %>
13
13
  <%= link_to 'First', jobs_path(status: params[:status], page: 1), class: 'pagination-link' %>
@@ -18,6 +18,10 @@
18
18
  <th>Priority</th>
19
19
  <td><%= @job[:priority] %></td>
20
20
  </tr>
21
+ <tr>
22
+ <th>Enqueued at</th>
23
+ <td><%= @job.dig(:args, 0, :enqueued_at).to_time.strftime("%Y-%m-%d %H:%M:%S") %></td>
24
+ </tr>
21
25
  <tr>
22
26
  <th>Run at</th>
23
27
  <td><%= @job[:run_at].strftime("%Y-%m-%d %H:%M:%S") %></td>
@@ -9,7 +9,7 @@
9
9
  <th>Running</th>
10
10
  <th>Finished</th>
11
11
  <th>Expired</th>
12
- <th>Latency</th>
12
+ <th>Latency (seconds)</th>
13
13
  </tr>
14
14
  </thead>
15
15
  <tbody>
@@ -21,7 +21,7 @@
21
21
  <td><%= link_to values[:running], jobs_path(status: 'running', queue_name: queue) %></td>
22
22
  <td><%= link_to values[:finished], jobs_path(status: 'finished', queue_name: queue) %></td>
23
23
  <td><%= link_to values[:expired], jobs_path(status: 'expired', queue_name: queue) %></td>
24
- <td></td>
24
+ <td><%= @queue_latencies[queue] %></td>
25
25
  </tr>
26
26
  <% end %>
27
27
  </tbody>
data/lib/que/view/dsl.rb CHANGED
@@ -19,6 +19,10 @@ module Que
19
19
  }
20
20
  end
21
21
 
22
+ def fetch_queue_latencies(queue_names)
23
+ queue_names.index_with { |queue_name| execute(fetch_queue_oldest_job_sql(queue_name)).dig(0, :enqueued_at) }
24
+ end
25
+
22
26
  def fetch_queue_names
23
27
  execute(fetch_queue_names_sql).map { |queues_data|
24
28
  ["#{queues_data[:queue_name]} (#{queues_data[:count_all]})", queues_data[:queue_name]]
@@ -137,6 +141,18 @@ module Que
137
141
  SQL
138
142
  end
139
143
 
144
+ def fetch_queue_oldest_job_sql(queue_name)
145
+ <<-SQL.squish
146
+ SELECT args #>> '{0, enqueued_at}' AS enqueued_at
147
+ FROM que_jobs
148
+ WHERE queue = '#{queue_name}'
149
+ AND expired_at IS NULL
150
+ AND finished_at IS NULL
151
+ ORDER BY args #>> '{0, enqueued_at}'
152
+ LIMIT 1
153
+ SQL
154
+ end
155
+
140
156
  def fetch_queue_names_sql
141
157
  <<-SQL.squish
142
158
  SELECT COUNT(*) AS count_all, queue AS queue_name
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Que
4
4
  module View
5
- VERSION = '0.3.2'
5
+ VERSION = '0.3.3'
6
6
  end
7
7
  end
data/lib/que/view.rb CHANGED
@@ -34,7 +34,7 @@ module Que
34
34
  end
35
35
 
36
36
  # Public: All the methods delegated to instance. These should match the interface of Que::View::DSL.
37
- def_delegators :instance, :fetch_dashboard_stats, :fetch_que_lockers, :fetch_queue_metrics,
37
+ def_delegators :instance, :fetch_dashboard_stats, :fetch_que_lockers, :fetch_queue_metrics, :fetch_queue_latencies,
38
38
  :fetch_queue_names, :fetch_job_names,
39
39
  :fetch_running_jobs, :fetch_failing_jobs, :fetch_scheduled_jobs, :fetch_finished_jobs,
40
40
  :fetch_expired_jobs, :fetch_job,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: que-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-03 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: que