Module: Restalk::ResqueAdapter

Defined in:
lib/restalk.rb

Defined Under Namespace

Classes: RestalkResqueJob

Instance Method Summary collapse

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


78
# File 'lib/restalk.rb', line 78

def connected?; true; end

#get_redis_object(url) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/restalk.rb', line 54

def get_redis_object(url)
  return url unless url['@']
  credentials, url = url.split '@'
  host, port = url.split ':'
  username, password = credentials.split ':'
  Redis.new(:host => host,
                     :port => port,
                     :username => username,
                     :password => password)
end

#init(server = nil, queue = nil) ⇒ Object



47
48
49
50
51
52
# File 'lib/restalk.rb', line 47

def init(server = nil, queue = nil)
  @queue = queue || ENV['RESQUE_QUEUE'] || 'restalk_queue'
  require 'resque'
  server = get_redis_object(server || ENV['REDIS'] || 'localhost:6379')
  Resque.redis = server
end

#popObject



69
70
71
72
# File 'lib/restalk.rb', line 69

def pop
  data = Resque.pop @queue
  return RestalkResqueJob.new data['args'].first if data
end

#push(data) ⇒ Object



65
66
67
# File 'lib/restalk.rb', line 65

def push(data)
  Resque.enqueue_to(@queue, RestalkResqueJob, data)
end

#statsObject



74
75
76
# File 'lib/restalk.rb', line 74

def stats
  Resque.info
end