mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 03:25:31 -05:00
33 lines
No EOL
593 B
Ruby
33 lines
No EOL
593 B
Ruby
module Jobs
|
|
class ClockworkHeartbeat < Jobs::Base
|
|
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
$redis.set last_heartbeat_at_key, Time.now.to_i
|
|
end
|
|
|
|
def self.is_clockwork_running?
|
|
if time = ClockworkHeartbeat.new.last_heartbeat_at
|
|
time > 2.minutes.ago
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
def last_heartbeat_at
|
|
if time_int = $redis.get(last_heartbeat_at_key)
|
|
Time.at(time_int.to_i)
|
|
else
|
|
nil
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def last_heartbeat_at_key
|
|
'clockwork:last_heartbeat_at'
|
|
end
|
|
|
|
end
|
|
end |