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.
968 969 970 |
# File 'lib/rrrspec/redis_models.rb', line 968 def initialize(slave_key) @key = slave_key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
966 967 968 |
# File 'lib/rrrspec/redis_models.rb', line 966 def key @key end |
Class Method Details
.build_from_pid(pid) ⇒ Object
978 979 980 981 |
# File 'lib/rrrspec/redis_models.rb', line 978 def self.build_from_pid(pid) slave_key = RRRSpec.make_key('rrrspec', 'worker', RRRSpec.hostname, 'slave', pid) return new(slave_key) end |
.create ⇒ Object
972 973 974 975 976 |
# File 'lib/rrrspec/redis_models.rb', line 972 def self.create slave_key = RRRSpec.make_key('rrrspec', 'worker', RRRSpec.hostname, 'slave', Process.getpgrp) slave = new(slave_key) return slave end |
Instance Method Details
#add_trial(trial) ⇒ Object
Public: Add trial to the list of the trials that the slave worked for.
997 998 999 1000 |
# File 'lib/rrrspec/redis_models.rb', line 997 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
1024 1025 1026 |
# File 'lib/rrrspec/redis_models.rb', line 1024 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
1034 1035 1036 |
# File 'lib/rrrspec/redis_models.rb', line 1034 def exist? RRRSpec.redis.exists(RRRSpec.make_key(key, 'heartbeat')) end |
#expire(sec) ⇒ Object
Persistence
1061 1062 1063 1064 1065 1066 |
# File 'lib/rrrspec/redis_models.rb', line 1061 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
1039 1040 1041 |
# File 'lib/rrrspec/redis_models.rb', line 1039 def heartbeat(time) RRRSpec.redis.setex(RRRSpec.make_key(key, 'heartbeat'), time, "alive") end |
#log ⇒ Object
Public: Execution log of the slave
1019 1020 1021 |
# File 'lib/rrrspec/redis_models.rb', line 1019 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”
1008 1009 1010 |
# File 'lib/rrrspec/redis_models.rb', line 1008 def status RRRSpec.redis.hget(key, 'status') end |
#to_h ⇒ Object
Serialize
1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/rrrspec/redis_models.rb', line 1046 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
1054 1055 1056 |
# File 'lib/rrrspec/redis_models.rb', line 1054 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
990 991 992 993 994 |
# File 'lib/rrrspec/redis_models.rb', line 990 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:
- “normal_exit”, “timeout_exit”, “failure_exit”
1014 1015 1016 |
# File 'lib/rrrspec/redis_models.rb', line 1014 def update_status(status) RRRSpec.redis.hset(key, 'status', status) end |