que-view 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b7b44890b63b063c130537e5fcc117f40bf1236dd89b156ca48e87a78d71248
4
- data.tar.gz: 629fd230eb265fdbe7a41f0aec19e37f4047d797750eb635612687cceb7d5af9
3
+ metadata.gz: fcbc566936eae22f23cba44ed6908437fba07dbf621128895f4fe4e40319ad61
4
+ data.tar.gz: a7f2213f756286321699a96f10e1b69c1578e91dff46daa877c37db41898efde
5
5
  SHA512:
6
- metadata.gz: 1412a8a378aaa977fd92b40c79dad153267cbf50d1e7ac7409380469106269e5b96484d12193ac57ee78187ad172e79a61783e54e0948aff9242e4947bf6d381
7
- data.tar.gz: ac32754839e4105584d330cc34a19cb5fccb48f8ce60afd58c1c3f5bb9b933a7ab4bd8616e109d7a2a5b91b384dff878b4a5699ee576f5d5fa1822c60d4392b0
6
+ metadata.gz: 6250a8886b4d258f080d4133caddff6292295d4a586dadf5b678fbb98052e59a78ec2de42eaa928dc6def2de8a2a0800e086528c150111f1b80c171405eac0de
7
+ data.tar.gz: 4a41eff359089fd195b47408a64f0fa94805c1230fbf40d3cbf2001f76e8e465040d78f79f8186411c4fa46a90d979b21b3bae3796c5524f6f98833844be24c3
@@ -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| value ? (current_time - value.to_time.to_i) : 0 }
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]]
@@ -90,7 +94,7 @@ module Que
90
94
  <<-SQL.squish
91
95
  SELECT count(*) AS total,
92
96
  count(locks.job_id) AS running,
93
- coalesce(sum((error_count > 0 AND locks.job_id IS NULL)::int), 0) AS failing,
97
+ coalesce(sum((error_count > 0 AND locks.job_id IS NULL AND expired_at IS NULL)::int), 0) AS failing,
94
98
  coalesce(sum((error_count = 0 AND locks.job_id IS NULL)::int), 0) AS scheduled,
95
99
  coalesce(sum((finished_at IS NOT NULL)::int), 0) AS finished,
96
100
  coalesce(sum((expired_at IS NOT NULL)::int), 0) AS expired
@@ -116,7 +120,7 @@ module Que
116
120
  CASE
117
121
  WHEN expired_at IS NOT NULL THEN 'expired'
118
122
  WHEN finished_at IS NOT NULL THEN 'finished'
119
- WHEN locks.job_id IS NULL AND error_count > 0 THEN 'failing'
123
+ WHEN locks.job_id IS NULL AND error_count > 0 AND expired_at IS NULL THEN 'failing'
120
124
  WHEN locks.job_id IS NULL AND error_count = 0 THEN 'scheduled'
121
125
  ELSE 'running'
122
126
  END status
@@ -130,13 +134,25 @@ module Que
130
134
  CASE
131
135
  WHEN expired_at IS NOT NULL THEN 'expired'
132
136
  WHEN finished_at IS NOT NULL THEN 'finished'
133
- WHEN locks.job_id IS NULL AND error_count > 0 THEN 'failing'
137
+ WHEN locks.job_id IS NULL AND error_count > 0 AND expired_at IS NULL THEN 'failing'
134
138
  WHEN locks.job_id IS NULL AND error_count = 0 THEN 'scheduled'
135
139
  ELSE 'running'
136
140
  END
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
@@ -158,6 +174,7 @@ module Que
158
174
  where_condition = <<-SQL.squish
159
175
  WHERE locks.job_id IS NULL
160
176
  AND error_count > 0
177
+ AND expired_at IS NULL
161
178
  #{search_condition(params)}
162
179
  SQL
163
180
  fetch_jobs_sql(per_page, offset, where_condition)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Que
4
4
  module View
5
- VERSION = '0.3.2'
5
+ VERSION = '0.3.4'
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.4
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: que