Class: RRRSpec::Slave
- Inherits:
-
Object
- Object
- RRRSpec::Slave
- 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
-
#add_trial(trial) ⇒ Object
Public: Add trial to the list of the trials that the slave worked for.
-
#append_log(string) ⇒ Object
Public: Append a line to the worker_log.
-
#exist? ⇒ Boolean
Public: Check its existence with heartbeat key.
-
#expire(sec) ⇒ Object
Persistence.
-
#heartbeat(time) ⇒ Object
Public: Maintain heartbeat.
-
#initialize(slave_key) ⇒ Slave
constructor
A new instance of Slave.
-
#log ⇒ Object
Public: Execution log of the slave.
-
#status ⇒ Object
Public: Current status.
-
#to_h ⇒ Object
Serialize.
- #to_json(options = nil) ⇒ Object
-
#trials ⇒ Object
Public: Returns the trials of the slave.
-
#update_status(status) ⇒ Object
Public: Update the status.
Constructor Details
#initialize(slave_key) ⇒ Slave
Returns a new instance of Slave.
936 937 938 |
# File 'lib/rrrspec/redis_models.rb', line 936 def initialize(slave_key) @key = slave_key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
934 935 936 |
# File 'lib/rrrspec/redis_models.rb', line 934 def key @key end |
Class Method Details
Instance Method Details
#add_trial(trial) ⇒ Object
Public: Add trial to the list of the trials that the slave worked for.
965 966 967 968 |
# File 'lib/rrrspec/redis_models.rb', line 965 def add_trial(trial) RRRSpec.redis.rpush(RRRSpec.make_key(key, 'trial'), trial.key) end |
#append_log(string) ⇒ Object
Public: Append a line to the worker_log
992 993 994 |
# File 'lib/rrrspec/redis_models.rb', line 992 def append_log(string) RRRSpec.redis.append(RRRSpec.make_key(key, 'log'), string) end |
#exist? ⇒ Boolean
Public: Check its existence with heartbeat key.
Returns bool
1002 1003 1004 |
# File 'lib/rrrspec/redis_models.rb', line 1002 def exist? RRRSpec.redis.exists(RRRSpec.make_key(key, 'heartbeat')) end |
#expire(sec) ⇒ Object
Persistence
1029 1030 1031 1032 1033 1034 |
# File 'lib/rrrspec/redis_models.rb', line 1029 def expire(sec) RRRSpec.redis.expire(key, sec) RRRSpec.redis.expire(RRRSpec.make_key(key, 'trial'), sec) RRRSpec.redis.expire(RRRSpec.make_key(key, 'log'), sec) RRRSpec.redis.expire(RRRSpec.make_key(key, 'heartbeat'), sec) end |
#heartbeat(time) ⇒ Object
Public: Maintain heartbeat
1007 1008 1009 |
# File 'lib/rrrspec/redis_models.rb', line 1007 def heartbeat(time) RRRSpec.redis.setex(RRRSpec.make_key(key, 'heartbeat'), time, "alive") end |
#log ⇒ Object
Public: Execution log of the slave
987 988 989 |
# File 'lib/rrrspec/redis_models.rb', line 987 def log RRRSpec.redis.get(RRRSpec.make_key(key, 'log')) || "" end |
#status ⇒ Object
Public: Current status
Returns either nil, “normal_exit”, “timeout_exit” or “failure_exit”
976 977 978 |
# File 'lib/rrrspec/redis_models.rb', line 976 def status RRRSpec.redis.hget(key, 'status') end |
#to_h ⇒ Object
Serialize
1014 1015 1016 1017 1018 1019 1020 |
# File 'lib/rrrspec/redis_models.rb', line 1014 def to_h h = RRRSpec.redis.hgetall(key) h['trials'] = trials.map { |trial| { 'key' => trial.key } } h['key'] = key h['log'] = log h end |
#to_json(options = nil) ⇒ Object
1022 1023 1024 |
# File 'lib/rrrspec/redis_models.rb', line 1022 def to_json(=nil) to_h.to_json() end |
#trials ⇒ Object
Public: Returns the trials of the slave. The return value should be sorted in the order added.
Returns an array of the Trials
958 959 960 961 962 |
# File 'lib/rrrspec/redis_models.rb', line 958 def trials RRRSpec.redis.lrange(RRRSpec.make_key(key, 'trial'), 0, -1).map do |key| Trial.new(key) end end |