Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NOW() from Dashboard SQL; fix chart x-axis order left-to-right, old-to-new #355

Merged
merged 1 commit into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions engine/app/assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
.tooltip.tooltip-hidden {
opacity: 0;
}

.ct-label.ct-horizontal {
white-space: nowrap;
}
1 change: 0 additions & 1 deletion engine/app/assets/vendor/bootstrap/bootstrap.bundle.min.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion engine/app/assets/vendor/bootstrap/bootstrap.min.css

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions engine/app/controllers/good_job/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def to_params(override)
def index
@filter = JobFilter.new(params)

job_data = GoodJob::Job.connection.exec_query Arel.sql(<<~SQL.squish)
count_query = Arel.sql(GoodJob::Job.pg_or_jdbc_query(<<~SQL.squish))
SELECT *
FROM generate_series(
date_trunc('hour', NOW() - '1 day'::interval),
date_trunc('hour', NOW()),
date_trunc('hour', $1::timestamp),
date_trunc('hour', $2::timestamp),
'1 hour'
) timestamp
LEFT JOIN (
Expand All @@ -76,13 +76,17 @@ def index
) sources
GROUP BY date_trunc('hour', scheduled_at), queue_name
) sources ON sources.scheduled_at = timestamp
ORDER BY timestamp DESC
ORDER BY timestamp ASC
SQL

current_time = Time.current
binds = [[nil, current_time - 1.day], [nil, current_time]]
job_data = GoodJob::Job.connection.exec_query(count_query, "GoodJob Dashboard Chart", binds)

queue_names = job_data.map { |d| d['queue_name'] }.uniq
labels = []
queues_data = job_data.to_a.group_by { |d| d['timestamp'] }.each_with_object({}) do |(timestamp, values), hash|
labels << timestamp.in_time_zone.to_s
labels << timestamp.in_time_zone.strftime('%H:%M %z')
queue_names.each do |queue_name|
(hash[queue_name] ||= []) << values.find { |d| d['queue_name'] == queue_name }&.[]('count')
end
Expand Down
2 changes: 1 addition & 1 deletion spec/test_app/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
start_date = 7.days.ago
time_increments = (1.minute..90.minutes).to_a
time_increments = (1.minute..10.minutes).to_a
job_classes = ['ExampleJob', 'OtherJob']
queue_names = ["default", "mice", "elephants"]

Expand Down