Skip to content

Commit

Permalink
Fix COALESCE timestamp generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bananatron committed Mar 29, 2024
1 parent b7abbaf commit a8d93c5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/charts/good_job/scheduled_by_queue_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def data
start_time = end_time - 1.day
table_name = GoodJob::Job.table_name

filtered_queue_schedule_query = @filter.filtered_query
.except(:select, :order)
.select(
:queue_name,
Arel::Nodes::NamedFunction.new(
'CAST',
[Arel.sql("COALESCE(#{table_name}.scheduled_at, #{table_name}.created_at) AS timestamp")]
).as('scheduled_at')
).to_sql

count_query = Arel.sql(GoodJob::Execution.pg_or_jdbc_query(<<~SQL.squish))
SELECT *
FROM generate_series(
Expand All @@ -24,7 +34,7 @@ def data
queue_name,
count(*) AS count
FROM (
#{@filter.filtered_query.except(:select, :order).select('queue_name', "COALESCE(#{table_name}.scheduled_at, #{table_name}.created_at)::timestamp AS scheduled_at").to_sql}
#{filtered_queue_schedule_query}
) sources
GROUP BY date_trunc('hour', scheduled_at), queue_name
) sources ON sources.scheduled_at = timestamp
Expand Down

0 comments on commit a8d93c5

Please sign in to comment.