Module: RRRSpec::ArbiterQueue

Defined in:
lib/rrrspec/redis_models.rb

Constant Summary collapse

ARBITER_QUEUE_KEY =
'rrrspec:arbiter_queue'

Class Method Summary collapse

Class Method Details

.cancel(taskset) ⇒ Object

Public: Cancel the taskset.



17
18
19
# File 'lib/rrrspec/redis_models.rb', line 17

def self.cancel(taskset)
  RRRSpec.redis.rpush(ARBITER_QUEUE_KEY, "cancel\t#{taskset.key}")
end

.check(taskset) ⇒ Object

Public: Check if there is no tasks left in the taskset.



27
28
29
# File 'lib/rrrspec/redis_models.rb', line 27

def self.check(taskset)
  RRRSpec.redis.rpush(ARBITER_QUEUE_KEY, "check\t#{taskset.key}")
end

.dequeueObject

Public: Dequeue the task.

Returns [command_name, arg]



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rrrspec/redis_models.rb', line 39

def self.dequeue
  _, line = RRRSpec.redis.blpop(ARBITER_QUEUE_KEY, 0)
  command, arg = line.split("\t", 2)
  case command
  when 'cancel', 'check', 'fail'
    arg = Taskset.new(arg)
  when 'trial'
    arg = Trial.new(arg)
  else
    raise 'Unknown command'
  end
  return command, arg
end

.fail(taskset) ⇒ Object

Public: Mark taskset failed



22
23
24
# File 'lib/rrrspec/redis_models.rb', line 22

def self.fail(taskset)
  RRRSpec.redis.rpush(ARBITER_QUEUE_KEY, "fail\t#{taskset.key}")
end

.trial(trial) ⇒ Object

Public: Update the status of the task based on the result of the trial.



32
33
34
# File 'lib/rrrspec/redis_models.rb', line 32

def self.trial(trial)
  RRRSpec.redis.rpush(ARBITER_QUEUE_KEY, "trial\t#{trial.key}")
end