Class: KSConnect
- Inherits:
-
Object
- Object
- KSConnect
- Includes:
- Logs
- Defined in:
- lib/ksconnect.rb,
lib/ksconnect/api.rb,
lib/ksconnect/helpers.rb,
lib/ksconnect/api/plugin.rb,
lib/ksconnect/api/plugin/data.rb,
lib/ksconnect/api/plugin/config.rb,
lib/ksconnect/api/plugin/domain.rb
Defined Under Namespace
Constant Summary collapse
- MIN_THREADS =
(ENV['MIN_THREADS'] || 5).to_i
- MAX_THREADS =
(ENV['MAX_THREADS'] || 25).to_i
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ KSConnect
constructor
A new instance of KSConnect.
Methods included from Logs
Constructor Details
#initialize(*args) ⇒ KSConnect
Returns a new instance of KSConnect.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ksconnect.rb', line 20 def initialize(*args) Redis.current ||= Redis.new(driver: :hiredis) $redis ||= ConnectionPool.new(size: MAX_THREADS, timeout: 8) { Redis.current } plugins = args = args.last.is_a?(Hash) ? args.last : nil if plugins.pop else = {} end @api = KSConnect::API.new(enabled_plugins: plugins, use_helpers: [:use_helpers]) end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
14 15 16 |
# File 'lib/ksconnect.rb', line 14 def api @api end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
15 16 17 |
# File 'lib/ksconnect.rb', line 15 def plugin @plugin end |
Class Method Details
.channel(name) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ksconnect.rb', line 41 def self.channel(name) Thread.start do begin Redis.new(driver: :hiredis).subscribe(name) do |on| logger.info "Subscribing to redis channel: #{name}" on. do |_channel, | thread_pool.process do begin yield rescue => error logger.error "#{error.} on redis channel #{name}:" logger.error error end end end end rescue => error logger.error "Fatal error on redis channel #{name}, restarting in 0.5s" logger.error error.backtrace.join("\n") sleep 0.5 retry end end end |
.thread_pool ⇒ Object
36 37 38 39 |
# File 'lib/ksconnect.rb', line 36 def self.thread_pool Thread::Pool.abort_on_exception = true @@thread_pool ||= Thread.pool(MIN_THREADS, MAX_THREADS) end |