8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/postqueue/cli/stats.rb', line 8
def stats(_options)
require "table_print"
sql = <<-SQL
SELECT op,
COUNT(*) AS count,
failed_attempts,
CASE
WHEN failed_attempts >= 5 THEN 'FAILED'
WHEN failed_attempts > 0 THEN 'RETRY'
WHEN next_run_at < now() THEN 'READY'
ELSE 'WAIT'
END AS status,
MIN(now() - created_at) AS min_age,
MAX(now() - created_at) AS max_age,
AVG(now() - created_at) AS avg_age
FROM #{Postqueue.item_class.table_name}
GROUP BY op, failed_attempts, status
SQL
recs = Postqueue.item_class.find_by_sql(sql)
tp recs, :status, :op, :failed_attempts, :count, :avg_age, :min_age, :max_age
end
|