Class: RRRSpec::Task
- Inherits:
-
Object
- Object
- RRRSpec::Task
- Defined in:
- lib/rrrspec/redis_models.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#add_trial(trial) ⇒ Object
Public: Add a trial of the task.
-
#estimate_sec ⇒ Object
Public: Estimate time to finishe the task.
-
#expire(sec) ⇒ Object
Persistence.
-
#initialize(task_key) ⇒ Task
constructor
A new instance of Task.
-
#spec_file ⇒ Object
Public: Spec file to run.
-
#status ⇒ Object
Public: Current status.
-
#taskset ⇒ Object
Public: Included taskset.
-
#to_h ⇒ Object
Serialize.
- #to_json(options = nil) ⇒ Object
-
#trials ⇒ Object
Public: Returns the trials of the task.
-
#update_status(status) ⇒ Object
Public: Update the status.
Constructor Details
#initialize(task_key) ⇒ Task
Returns a new instance of Task.
582 583 584 |
# File 'lib/rrrspec/redis_models.rb', line 582 def initialize(task_key) @key = task_key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
580 581 582 |
# File 'lib/rrrspec/redis_models.rb', line 580 def key @key end |
Class Method Details
.create(taskset, estimate_sec, spec_file) ⇒ Object
586 587 588 589 590 591 592 593 594 595 |
# 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 |
Instance Method Details
#==(other) ⇒ Object
597 598 599 |
# File 'lib/rrrspec/redis_models.rb', line 597 def ==(other) @key == other.key end |
#add_trial(trial) ⇒ Object
Public: Add a trial of the task.
640 641 642 643 |
# 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 ⇒ Object
Public: Estimate time to finishe the task.
Returns seconds or nil if there is no estimation
607 608 609 610 |
# 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) ⇒ Object
Persistence
684 685 686 687 688 |
# 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 ⇒ Object
Public: Spec file to run.
Returns a path to the spec
615 616 617 |
# File 'lib/rrrspec/redis_models.rb', line 615 def spec_file RRRSpec.redis.hget(key, 'spec_file') end |
#status ⇒ Object
Public: Current status
Returns either nil, “running”, “passed”, “pending” or “failed”
651 652 653 |
# File 'lib/rrrspec/redis_models.rb', line 651 def status RRRSpec.redis.hget(key, 'status') end |
#taskset ⇒ Object
Public: Included taskset
Returns a Taskset
622 623 624 |
# File 'lib/rrrspec/redis_models.rb', line 622 def taskset Taskset.new(RRRSpec.redis.hget(key, 'taskset')) end |
#to_h ⇒ Object
Serialize
668 669 670 671 672 673 674 675 |
# 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) ⇒ Object
677 678 679 |
# File 'lib/rrrspec/redis_models.rb', line 677 def to_json(=nil) to_h.to_json() end |
#trials ⇒ Object
Public: Returns the trials of the task. The return value should be sorted in the order added.
Returns an array of the Trials
633 634 635 636 637 |
# 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) ⇒ Object
Public: Update the status. It should be one of:
- nil, “running”, “passed”, “pending”, “failed”
657 658 659 660 661 662 663 |
# 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 |