Class: SolidQueueTui::Connection
- Inherits:
-
Object
- Object
- SolidQueueTui::Connection
- Defined in:
- lib/solid_queue_tui/connection.rb
Defined Under Namespace
Classes: ConnectionError
Constant Summary collapse
- CONFIG_FILE =
"config/solid_tui.yml"
Class Method Summary collapse
-
.establish! ⇒ Object
Loads config, establishes the DB connection, and returns the parsed config hash.
- .load_config ⇒ Object
- .verify_solid_queue_tables! ⇒ Object
Class Method Details
.establish! ⇒ Object
Loads config, establishes the DB connection, and returns the parsed config hash.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/solid_queue_tui/connection.rb', line 11 def self.establish! config = load_config url = config["database_url"] raise ConnectionError, <<~MSG unless url No database_url found in #{CONFIG_FILE}. Create #{CONFIG_FILE} with: database_url: postgres://user:pass@localhost/myapp_queue refresh: 2 MSG ActiveRecord::Base.establish_connection(url) verify_solid_queue_tables! config end |
.load_config ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/solid_queue_tui/connection.rb', line 29 def self.load_config path = File.join(Dir.pwd, CONFIG_FILE) unless File.exist?(path) raise ConnectionError, <<~MSG Config file not found: #{CONFIG_FILE} Create #{CONFIG_FILE} with: database_url: postgres://user:pass@localhost/myapp_queue refresh: 2 MSG end YAML.safe_load(File.read(path), permitted_classes: [Symbol]) || {} end |
.verify_solid_queue_tables! ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/solid_queue_tui/connection.rb', line 45 def self.verify_solid_queue_tables! conn = ActiveRecord::Base.connection required = %w[solid_queue_jobs solid_queue_ready_executions] missing = required.reject { |t| conn.table_exists?(t) } unless missing.empty? raise ConnectionError, "Missing Solid Queue tables: #{missing.join(', ')}. " \ "Is this a Solid Queue database?" end end |