From fe0d7c5874c94f948997b39b905a8e49e2a3db35 Mon Sep 17 00:00:00 2001 From: PH Munhoz Date: Sun, 15 Mar 2026 19:30:32 -0300 Subject: [PATCH 1/2] feat: add Mysql chart compatibility --- .../solid_queue_monitor/chart_data_service.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/services/solid_queue_monitor/chart_data_service.rb b/app/services/solid_queue_monitor/chart_data_service.rb index 6b9fce6..667b15b 100644 --- a/app/services/solid_queue_monitor/chart_data_service.rb +++ b/app/services/solid_queue_monitor/chart_data_service.rb @@ -81,16 +81,21 @@ def fill_buckets(buckets, index_counts) # Cross-DB bucket index expression. # PostgreSQL: CAST((EXTRACT(EPOCH FROM col) - start) / interval AS INTEGER) # SQLite: CAST((CAST(strftime('%s', col) AS INTEGER) - start) / interval AS INTEGER) + # MySQL: CAST((UNIX_TIMESTAMP(col) - start) / interval AS SIGNED) def bucket_index_expr(column, start_epoch, interval_seconds) - if sqlite? + case + when adapter?('sqlite') "CAST((CAST(strftime('%s', #{column}) AS INTEGER) - #{start_epoch}) / #{interval_seconds} AS INTEGER)" + when adapter?('mysql') + "CAST((UNIX_TIMESTAMP(#{column}) - #{start_epoch}) / #{interval_seconds} AS SIGNED)" else "CAST((EXTRACT(EPOCH FROM #{column}) - #{start_epoch}) / #{interval_seconds} AS INTEGER)" end end - def sqlite? - ActiveRecord::Base.connection.adapter_name.downcase.include?('sqlite') + def adapter?(name) + ActiveRecord::Base.connection.adapter_name.downcase.include?(name) end + end end From 0aae8cac102c4f657c62f7cff9b9ff753232b0b8 Mon Sep 17 00:00:00 2001 From: PH Munhoz Date: Mon, 16 Mar 2026 08:31:26 -0300 Subject: [PATCH 2/2] fix: Rubocop issues --- app/services/solid_queue_monitor/chart_data_service.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/services/solid_queue_monitor/chart_data_service.rb b/app/services/solid_queue_monitor/chart_data_service.rb index 667b15b..6384099 100644 --- a/app/services/solid_queue_monitor/chart_data_service.rb +++ b/app/services/solid_queue_monitor/chart_data_service.rb @@ -83,10 +83,9 @@ def fill_buckets(buckets, index_counts) # SQLite: CAST((CAST(strftime('%s', col) AS INTEGER) - start) / interval AS INTEGER) # MySQL: CAST((UNIX_TIMESTAMP(col) - start) / interval AS SIGNED) def bucket_index_expr(column, start_epoch, interval_seconds) - case - when adapter?('sqlite') + if adapter?('sqlite') "CAST((CAST(strftime('%s', #{column}) AS INTEGER) - #{start_epoch}) / #{interval_seconds} AS INTEGER)" - when adapter?('mysql') + elsif adapter?('mysql') "CAST((UNIX_TIMESTAMP(#{column}) - #{start_epoch}) / #{interval_seconds} AS SIGNED)" else "CAST((EXTRACT(EPOCH FROM #{column}) - #{start_epoch}) / #{interval_seconds} AS INTEGER)" @@ -96,6 +95,5 @@ def bucket_index_expr(column, start_epoch, interval_seconds) def adapter?(name) ActiveRecord::Base.connection.adapter_name.downcase.include?(name) end - end end