Fix drb_counter

This commit is contained in:
2022-01-31 16:26:43 -05:00
parent 711cd95ad4
commit 9901506a2d
+7 -3
View File
@@ -3,6 +3,8 @@
# See Dockerfile for run instructions
require 'rubygems'
require 'drb/drb'
require 'erb'
require 'couchrest'
#require 'pry'
#require File.expand_path('../lib/in_memory_q_counter', File.dirname(__FILE__))
# This is a non thread safe replacement for the
@@ -67,7 +69,8 @@ class InMemoryQCounter
couch_settings_path = 'config/couchdb.yml'
puts "Couch settings path: #{couch_settings_path}"
puts "Environment: #{environment.inspect}"
couch_settings = YAML.load_file(couch_settings_path)[environment]
#couch_settings = YAML.load_file(couch_settings_path)[environment]
couch_settings = YAML.safe_load(ERB.new(File.read(couch_settings_path)).result, [Symbol], [], ['default'])[environment]
database = couch_settings['database']
db = CouchRest.database(database) # for debug: db = CouchPotato.database.couchrest_database
design_doc = "_design/order_counter"
@@ -75,7 +78,7 @@ class InMemoryQCounter
tries = 0
begin
view_result = db.view(view_path, reduce: true, group: true, group_level: 2)
rescue RestClient::ResourceNotFound => e
rescue CouchRest::NotFound => e
puts "Database view #{view_path} not found"
design_doc_path = File.expand_path('../couchdb_design.yml', __FILE__)
doc = YAML.load_file design_doc_path
@@ -107,5 +110,6 @@ class InMemoryQCounter
end
drb_port = 9022
environment = (%w[production staging development test] & [ENV['DRB_ENV']]).first || 'development'
DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: environment == 'production', environment: environment)
#InMemoryQCounter.new(reload_stats: true, environment: environment)
DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment)
DRb.thread.join