lib/zhong.rb in zhong-0.1.8 vs lib/zhong.rb in zhong-0.1.9
- old
+ new
@@ -39,11 +39,23 @@
def self.latest_heartbeat
all_heartbeats.map { |h| h[:last_seen] }.sort.last
end
def self.all_heartbeats
- Zhong::Util.safe_mget(Zhong.redis.scan_each(match: "zhong:heartbeat:*").to_a).map do |k, v|
- host, pid = k.split("zhong:heartbeat:", 2)[1].split("#", 2)
+ heartbeat_key = scheduler.config[:heartbeat_key]
+ heartbeats = Zhong.redis.hgetall(heartbeat_key)
+ now = redis_time
+
+ old_beats, new_beats = heartbeats.partition do |_, v|
+ Time.at(v.to_i) < (now - 15.minutes)
+ end
+
+ redis.multi do
+ old_beats.each { |b| Zhong.redis.hdel(heartbeat_key, b) }
+ end
+
+ new_beats.map do |k, v|
+ host, pid = k.split("#", 2)
{host: host, pid: pid, last_seen: Time.at(v.to_i)}
end
end
def self.logger