Module: Resque::Plugins::ResqueSliders::Helpers
Instance Method Summary collapse
-
#check_signal(host) ⇒ Object
Gets signal field in redis config_key for this host.
- #host_config_key ⇒ Object
- #key_prefix ⇒ Object
- #pause?(host) ⇒ Boolean
-
#queue_values(host) ⇒ Object
Return Hash: { queue => # }.
- #redis_del_hash(key, field) ⇒ Object
- #redis_get_hash(key) ⇒ Object
- #redis_get_hash_field(key, field) ⇒ Object
- #redis_set_hash(key, field, fvalue) ⇒ Object
- #register_setting(setting, value) ⇒ Object
- #reload?(host) ⇒ Boolean
-
#set_signal_flag(sig, host = @hostname) ⇒ Object
Set signal key given signal, host.
- #stop?(host) ⇒ Boolean
- #unregister_setting(setting) ⇒ Object
Instance Method Details
#check_signal(host) ⇒ Object
Gets signal field in redis config_key for this host. Don’t call directly
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/resque-sliders/helpers.rb', line 46 def check_signal(host) sig = caller[0][/`([^']*)'/, 1].gsub('?', '') raise 'Dont call me that' unless %w(reload pause stop).include?(sig) if @hostname # if instance variable set from running daemon, make a freshy redis_get_hash_field(host_config_key, "#{@hostname}:#{sig}").to_i == 1 ? true : false else # otherwise cache call in a Hash @host_signal_map ||= {} @host_signal_map[host] ||= {} unless @host_signal_map[host].has_key?(sig) @host_signal_map[host] = {sig => redis_get_hash_field(host_config_key, "#{host}:#{sig}").to_i == 1 ? true : false}.update(@host_signal_map[host]) end @host_signal_map[host][sig] end end |
#host_config_key ⇒ Object
10 11 12 |
# File 'lib/resque-sliders/helpers.rb', line 10 def host_config_key "plugins:resque-sliders:host_configs" end |
#key_prefix ⇒ Object
6 7 8 |
# File 'lib/resque-sliders/helpers.rb', line 6 def key_prefix "plugins:resque-sliders" end |
#pause?(host) ⇒ Boolean
67 68 69 |
# File 'lib/resque-sliders/helpers.rb', line 67 def pause?(host) check_signal(host) end |
#queue_values(host) ⇒ Object
Return Hash: { queue => # }
31 32 33 |
# File 'lib/resque-sliders/helpers.rb', line 31 def queue_values(host) redis_get_hash("#{key_prefix}:#{host}") end |
#redis_del_hash(key, field) ⇒ Object
26 27 28 |
# File 'lib/resque-sliders/helpers.rb', line 26 def redis_del_hash(key, field) Resque.redis.hdel(key, field) == 1 ? true : false end |
#redis_get_hash(key) ⇒ Object
14 15 16 |
# File 'lib/resque-sliders/helpers.rb', line 14 def redis_get_hash(key) Resque.redis.hgetall(key) end |
#redis_get_hash_field(key, field) ⇒ Object
18 19 20 |
# File 'lib/resque-sliders/helpers.rb', line 18 def redis_get_hash_field(key, field) Resque.redis.hget(key, field) end |
#redis_set_hash(key, field, fvalue) ⇒ Object
22 23 24 |
# File 'lib/resque-sliders/helpers.rb', line 22 def redis_set_hash(key, field, fvalue) Resque.redis.hset(key, field, fvalue) == 1 ? true : false end |
#register_setting(setting, value) ⇒ Object
35 36 37 |
# File 'lib/resque-sliders/helpers.rb', line 35 def register_setting(setting, value) redis_set_hash(host_config_key, "#{@hostname}:#{setting}", value) end |
#reload?(host) ⇒ Boolean
63 64 65 |
# File 'lib/resque-sliders/helpers.rb', line 63 def reload?(host) check_signal(host) end |
#set_signal_flag(sig, host = @hostname) ⇒ Object
Set signal key given signal, host
76 77 78 79 80 81 82 83 |
# File 'lib/resque-sliders/helpers.rb', line 76 def set_signal_flag(sig, host=@hostname) @hostname ||= host if sig == 'play' %w(pause stop).each { |x| unregister_setting(x) } else register_setting(sig, 1) end end |
#stop?(host) ⇒ Boolean
71 72 73 |
# File 'lib/resque-sliders/helpers.rb', line 71 def stop?(host) check_signal(host) end |
#unregister_setting(setting) ⇒ Object
39 40 41 |
# File 'lib/resque-sliders/helpers.rb', line 39 def unregister_setting(setting) redis_del_hash(host_config_key, "#{@hostname}:#{setting}") end |