class Antelopes::Puller

Class used to pull jobs This should not be used directly by Antelopes users.

@since 0.0.1 @private

Attributes

logger[R]
redis[R]

Public Class Methods

new(logger: nil, redis: nil) click to toggle source

Initialization

@param logger [ServerEngine::DaemonLogger] a logger @param redis [Redis] a {github.com/redis/redis-rb redis} connection

# File lib/antelopes/puller.rb, line 14
def initialize(logger: nil, redis: nil)
  @logger = logger || ServerEngine::DaemonLogger.new($stdout)
  @redis = redis || Antelopes::Redis.new.connection
end

Public Instance Methods

next_todo() click to toggle source

Method used by the workers to get a job to work on. When the job is started, it goes in the 'doing' list.

@return [Hash] the job

# File lib/antelopes/puller.rb, line 23
def next_todo
  jid = redis.brpoplpush('antelopes:todo', 'antelopes:doing', timeout: 1)

  return if jid.nil?
  Job.new(JSON.parse(redis.get("antelopes:job:#{jid}")))
end