Class: PgqPrometheus::SqlCaller::ActiveRecord
- Inherits:
-
Object
- Object
- PgqPrometheus::SqlCaller::ActiveRecord
- Defined in:
- lib/pgq_prometheus/sql_caller/active_record.rb
Instance Method Summary collapse
-
#consumer_info(queue, consumer = nil) ⇒ Hash<Symbol>+
Returns pgq.get_consumer_info for one or all consumers of queue.
-
#initialize(model_class_name) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
-
#queue_info(queue = nil) ⇒ Hash<Symbol>+
Returns pgq.get_queue_info for one or all queues.
-
#release_connection ⇒ Object
Releases active pg connection in thread.
-
#with_connection { ... } ⇒ Object
Acquires pg connection during block execution.
Constructor Details
#initialize(model_class_name) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
14 15 16 |
# File 'lib/pgq_prometheus/sql_caller/active_record.rb', line 14 def initialize(model_class_name) @model_class_name = model_class_name.to_s end |
Instance Method Details
#consumer_info(queue, consumer = nil) ⇒ Hash<Symbol>+
Returns pgq.get_consumer_info for one or all consumers of queue.
35 36 37 38 39 40 41 |
# File 'lib/pgq_prometheus/sql_caller/active_record.rb', line 35 def consumer_info(queue, consumer = nil) if consumer select_hashes('SELECT * FROM pgq.get_consumer_info(?, ?)', queue.to_s, consumer.to_s).first else select_hashes('SELECT * FROM pgq.get_consumer_info(?)', queue.to_s) end end |
#queue_info(queue = nil) ⇒ Hash<Symbol>+
Returns pgq.get_queue_info for one or all queues.
22 23 24 25 26 27 28 |
# File 'lib/pgq_prometheus/sql_caller/active_record.rb', line 22 def queue_info(queue = nil) if queue select_hashes('SELECT * FROM pgq.get_queue_info(?)', queue.to_s).first else select_hashes('SELECT * FROM pgq.get_queue_info()') end end |
#release_connection ⇒ Object
Releases active pg connection in thread. Do nothing if no connection captured.
45 46 47 |
# File 'lib/pgq_prometheus/sql_caller/active_record.rb', line 45 def release_connection model_class.connection_pool.release_connection end |
#with_connection { ... } ⇒ Object
Acquires pg connection during block execution. Release it after block executed.
52 53 54 |
# File 'lib/pgq_prometheus/sql_caller/active_record.rb', line 52 def with_connection model_class.connection_pool.with_connection { yield } end |