Module: HotPotato::Core
- Included in:
- AppTaskInfo, Admin, AppTask, AppTaskServer, Cache, QueueLogger, Route::AppTask, SupervisorServer, SupervisorInfo
- Defined in:
- lib/hot_potato/core.rb
Constant Summary collapse
- CONFIG_PATH =
"#{APP_PATH}/config/config.yml"
Instance Method Summary collapse
- #acquire_lock(key, duration = 10) ⇒ Object
- #config ⇒ Object
- #log ⇒ Object
- #queue_inject(name, message) ⇒ Object
- #queue_subscribe(name, &block) ⇒ Object
- #release_lock(key) ⇒ Object
- #set_logger(provider, options = {}) ⇒ Object
- #stat ⇒ Object
Instance Method Details
#acquire_lock(key, duration = 10) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/hot_potato/core.rb', line 46 def acquire_lock(key, duration = 10) if !stat.getset("hotpotato.lock.#{key.to_s}", "1") stat.expire "hotpotato.lock.#{key.to_s}", duration return true else stat.expire "hotpotato.lock.#{key.to_s}", duration return false end end |
#config ⇒ Object
24 25 26 |
# File 'lib/hot_potato/core.rb', line 24 def config @@config ||= YAML.load_file(CONFIG_PATH)[RACK_ENV] end |
#log ⇒ Object
18 19 20 21 22 |
# File 'lib/hot_potato/core.rb', line 18 def log @@log ||= Logger.new(STDOUT) @@log.level = Logger::INFO return @@log end |
#queue_inject(name, message) ⇒ Object
32 33 34 35 |
# File 'lib/hot_potato/core.rb', line 32 def queue_inject(name, ) @@queue ||= Redis.new :host => config['redis_hostname'], :port => config['redis_port'] @@queue.publish name.to_sym, Snappy.deflate(.to_json) end |
#queue_subscribe(name, &block) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/hot_potato/core.rb', line 37 def queue_subscribe(name, &block) queue ||= Redis.new :host => config['redis_hostname'], :port => config['redis_port'] queue.subscribe(*name) do |on| on. do |channel, | yield JSON.parse(Snappy.inflate()) end end end |
#release_lock(key) ⇒ Object
56 57 58 |
# File 'lib/hot_potato/core.rb', line 56 def release_lock(key) stat.del("hotpotato.lock.#{key.to_s}") end |
#set_logger(provider, options = {}) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/hot_potato/core.rb', line 10 def set_logger(provider, = {}) if provider == :queue_logger @@log ||= QueueLogger.new() else @@log ||= Logger.new(STDOUT) end end |