Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix psuedo heartbeating when HB file missing
With the previous version of this code, the validate_heartbeat code: def validate_heartbeat(w) last_heartbeat = workers_last_heartbeat(w) if w.last_heartbeat.nil? last_heartbeat ||= Time.now.utc w.update_attributes(:last_heartbeat => last_heartbeat) elsif !last_heartbeat.nil? && last_heartbeat > w.last_heartbeat w.update_attributes(:last_heartbeat => last_heartbeat) end end Would update the `last_heartbeat` value for the worker every time `validate_heartbeat` was called, which is not the intent. When working correctly, the validate_heartbeat code should: * If no value is set in the DB, initialize it to either the time pulled from workers_last_heartbeat, or the current time (this should only happen the first time this method is called for this worker) * If workers_last_heartbeat is not nil, and it is a more resent heartbeat time, update the DB with the new value Otherwise, assume we have the most up to date heartbeat value in the DB. This change just returns `nil` if we don't have anything to provide from the heartbeat file. This is fine since the `validate_heartbeat` method will take care of any initialization of the last_heartbeat value in the DB, so workers_last_heartbeat_to_file is just an existence check, plus a value if there is one.
- Loading branch information