class RRRSpec::Task

Attributes

key[R]

Public Class Methods

create(taskset, estimate_sec, spec_file) click to toggle source
# File lib/rrrspec/redis_models.rb, line 586
def self.create(taskset, estimate_sec, spec_file)
  task_key = RRRSpec.make_key(taskset.key, 'task', spec_file)
  RRRSpec.redis.hmset(
    task_key,
    'taskset', taskset.key,
    'estimate_sec', estimate_sec,
    'spec_file', spec_file
  )
  return new(task_key)
end
new(task_key) click to toggle source
# File lib/rrrspec/redis_models.rb, line 582
def initialize(task_key)
  @key = task_key
end

Public Instance Methods

==(other) click to toggle source
# File lib/rrrspec/redis_models.rb, line 597
def ==(other)
  @key == other.key
end
add_trial(trial) click to toggle source

Public: Add a trial of the task.

# File lib/rrrspec/redis_models.rb, line 640
def add_trial(trial)
  RRRSpec.redis.rpush(RRRSpec.make_key(key, 'trial'),
                      trial.key)
end
estimate_sec() click to toggle source

Public: Estimate time to finishe the task.

Returns seconds or nil if there is no estimation

# File lib/rrrspec/redis_models.rb, line 607
def estimate_sec
  v = RRRSpec.redis.hget(key, 'estimate_sec')
  v.present? ? v.to_i : nil
end
expire(sec) click to toggle source

Persistence

# File lib/rrrspec/redis_models.rb, line 684
def expire(sec)
  trials.each { |trial| trial.expire(sec) }
  RRRSpec.redis.expire(key, sec)
  RRRSpec.redis.expire(RRRSpec.make_key(key, 'trial'), sec)
end
spec_file() click to toggle source

Public: Spec file to run.

Returns a path to the spec

# File lib/rrrspec/redis_models.rb, line 615
def spec_file
  RRRSpec.redis.hget(key, 'spec_file')
end
status() click to toggle source

Public: Current status

Returns either nil, “running”, “passed”, “pending” or “failed”

# File lib/rrrspec/redis_models.rb, line 651
def status
  RRRSpec.redis.hget(key, 'status')
end
taskset() click to toggle source

Public: Included taskset

Returns a Taskset

# File lib/rrrspec/redis_models.rb, line 622
def taskset
  Taskset.new(RRRSpec.redis.hget(key, 'taskset'))
end
to_h() click to toggle source

Serialize

# File lib/rrrspec/redis_models.rb, line 668
def to_h
  h = RRRSpec.redis.hgetall(key)
  h['key'] = key
  h['trials'] = trials.map { |trial| { 'key' => trial.key } }
  h['taskset'] = { 'key' => h['taskset'] }
  RRRSpec.convert_if_present(h, 'estimate_sec') { |v| v.to_i }
  h
end
to_json(options=nil) click to toggle source
# File lib/rrrspec/redis_models.rb, line 677
def to_json(options=nil)
  to_h.to_json(options)
end
trials() click to toggle source

Public: Returns the trials of the task. The return value should be sorted in the order added.

Returns an array of the Trials

# File lib/rrrspec/redis_models.rb, line 633
def trials
  RRRSpec.redis.lrange(RRRSpec.make_key(key, 'trial'), 0, -1).map do |key|
    Trial.new(key)
  end
end
update_status(status) click to toggle source

Public: Update the status. It should be one of:

nil, “running”, “passed”, “pending”, “failed”
# File lib/rrrspec/redis_models.rb, line 657
def update_status(status)
  if status.present?
    RRRSpec.redis.hset(key, 'status', status)
  else
    RRRSpec.redis.hdel(key, 'status')
  end
end