solid_queue_monitor 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f1ef08bb05ef11d7b29d511beea231cab0d1a8e1b16fc88d6c0d1fd540660b1
4
- data.tar.gz: 310ff85731b0aa63432b03f909b39eb942a0eeccf59fc4956673c50561f70582
3
+ metadata.gz: 56966f46d6a81a73664fcad0850d60beeb87390264b9b2faf1a05d6031d38462
4
+ data.tar.gz: d064fc3683c29079fa20abd92e3d01487392de7d4c66d66bcd402571e8d059a3
5
5
  SHA512:
6
- metadata.gz: a7df976149fe809482b5a7a2299a431957174582d5134b7080942420595a469a645fae5541082a326e035b3b05fbc355f001d31eb06377b7a1275101139f735a
7
- data.tar.gz: 4e32adbbba30b69d0eea3eb106d68172d8d35ae00a3ae111eb1f560337bee25708b63d5654466cd1c47e49a1d37e3e51979e2a51ac6e5412f975ad00be1a798e
6
+ metadata.gz: 357596c47791d62224e737243db5fc183eb351988caffa55cedbe351f58562ff83c8fe8f3d65fdfcb1f3de976a890963d6aa1ad68cfb88037ff0d3410ec09160
7
+ data.tar.gz: aa2d8088de150fa65142d8b39088801c22b29f0fba914a74f4bf3240e2cd5017c9c48892c9ff5669a93f8526c767b0fe4146cf12b709485f726764af0d03cef6
@@ -61,7 +61,7 @@ module SolidQueueMonitor
61
61
  # This works identically on PostgreSQL and SQLite.
62
62
  def bucket_counts(model, column, start_time, end_time, interval, exclude_nil: false)
63
63
  start_epoch = start_time.to_i
64
- expr = bucket_index_expr(column, start_epoch, interval)
64
+ expr = bucket_index_expr(model, column, start_epoch, interval)
65
65
 
66
66
  scope = model.where(column => start_time..end_time)
67
67
  scope = scope.where.not(column => nil) if exclude_nil
@@ -82,18 +82,23 @@ module SolidQueueMonitor
82
82
  # PostgreSQL: CAST((EXTRACT(EPOCH FROM col) - start) / interval AS INTEGER)
83
83
  # SQLite: CAST((CAST(strftime('%s', col) AS INTEGER) - start) / interval AS INTEGER)
84
84
  # MySQL: CAST((UNIX_TIMESTAMP(col) - start) / interval AS SIGNED)
85
- def bucket_index_expr(column, start_epoch, interval_seconds)
86
- if adapter?('sqlite')
85
+ #
86
+ # The adapter is detected from the model's own connection, not
87
+ # ActiveRecord::Base's. Solid Queue is commonly hosted on a dedicated
88
+ # database (config.solid_queue.connects_to), which may use a different
89
+ # engine than the host app's primary connection.
90
+ def bucket_index_expr(model, column, start_epoch, interval_seconds)
91
+ if adapter?(model, 'sqlite')
87
92
  "CAST((CAST(strftime('%s', #{column}) AS INTEGER) - #{start_epoch}) / #{interval_seconds} AS INTEGER)"
88
- elsif adapter?('mysql') || adapter?('trilogy')
93
+ elsif adapter?(model, 'mysql') || adapter?(model, 'trilogy')
89
94
  "FLOOR((UNIX_TIMESTAMP(#{column}) - #{start_epoch}) / #{interval_seconds})"
90
95
  else
91
96
  "FLOOR((EXTRACT(EPOCH FROM #{column}) - #{start_epoch}) / #{interval_seconds})::integer"
92
97
  end
93
98
  end
94
99
 
95
- def adapter?(name)
96
- ActiveRecord::Base.connection.adapter_name.downcase.include?(name)
100
+ def adapter?(model, name)
101
+ model.connection.adapter_name.downcase.include?(name)
97
102
  end
98
103
  end
99
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidQueueMonitor
4
- VERSION = '2.2.0'
4
+ VERSION = '2.2.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_queue_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vishal Sadriya