mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
33 lines
593 B
Ruby
33 lines
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 |