module Resque::Plugins::ResqueSliders::Helpers

Public Instance Methods

add_to_known_hosts(hostname) click to toggle source
# File lib/resque-sliders/helpers.rb, line 21
def add_to_known_hosts(hostname)
  # add a hostname to the hosts set
  Resque.redis.sadd(known_hosts_key, hostname)
end
check_signal(host) click to toggle source

Gets signal field in redis config_key for this host. Don’t call directly

# File lib/resque-sliders/helpers.rb, line 62
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
  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}.update(@host_signal_map[host])
    end
    @host_signal_map[host][sig]
  end
end
del_from_known_hosts(hostname) click to toggle source
# File lib/resque-sliders/helpers.rb, line 26
def del_from_known_hosts(hostname)
  Resque.redis.srem(known_hosts_key, hostname)
end
host_config_key() click to toggle source

we store everything in this hash

# File lib/resque-sliders/helpers.rb, line 12
def host_config_key
  "#{key_prefix}:host_configs"
end
key_prefix() click to toggle source

prefix to all keys our plugin uses in redis

# File lib/resque-sliders/helpers.rb, line 7
def key_prefix
  "plugins:resque-sliders"
end
known_hosts_key() click to toggle source

used to keep track of hosts we know about

# File lib/resque-sliders/helpers.rb, line 17
def known_hosts_key
  "#{key_prefix}:known_hosts"
end
pause?(host) click to toggle source
# File lib/resque-sliders/helpers.rb, line 83
def pause?(host)
  check_signal(host)
end
queue_values(host) click to toggle source

Return Hash: { queue => # }

# File lib/resque-sliders/helpers.rb, line 47
def queue_values(host)
  redis_get_hash("#{key_prefix}:#{host}")
end
redis_del_hash(key, field) click to toggle source
# File lib/resque-sliders/helpers.rb, line 42
def redis_del_hash(key, field)
  Resque.redis.hdel(key, field) == 1
end
redis_get_hash(key) click to toggle source
# File lib/resque-sliders/helpers.rb, line 30
def redis_get_hash(key)
  Resque.redis.hgetall(key)
end
redis_get_hash_field(key, field) click to toggle source
# File lib/resque-sliders/helpers.rb, line 34
def redis_get_hash_field(key, field)
  Resque.redis.hget(key, field)
end
redis_set_hash(key, field, fvalue) click to toggle source
# File lib/resque-sliders/helpers.rb, line 38
def redis_set_hash(key, field, fvalue)
  Resque.redis.hset(key, field, fvalue) == 1
end
register_setting(setting, value) click to toggle source
# File lib/resque-sliders/helpers.rb, line 51
def register_setting(setting, value)
  redis_set_hash(host_config_key, "#{@hostname}:#{setting}", value)
end
reload?(host) click to toggle source
# File lib/resque-sliders/helpers.rb, line 79
def reload?(host)
  check_signal(host)
end
set_signal_flag(sig, host=@hostname) click to toggle source

Set signal key given signal, host

# File lib/resque-sliders/helpers.rb, line 92
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) click to toggle source
# File lib/resque-sliders/helpers.rb, line 87
def stop?(host)
  check_signal(host)
end
unregister_setting(setting) click to toggle source
# File lib/resque-sliders/helpers.rb, line 55
def unregister_setting(setting)
  redis_del_hash(host_config_key, "#{@hostname}:#{setting}")
end