forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dashboard warning when clockwork doesn't seem to be running
- Loading branch information
Showing
6 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Jobs | ||
class ClockworkHeartbeat < Jobs::Base | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
require 'jobs' | ||
|
||
describe Jobs::ClockworkHeartbeat do | ||
|
||
describe '#is_clockwork_running?' do | ||
|
||
subject { Jobs::ClockworkHeartbeat.is_clockwork_running? } | ||
|
||
it 'returns false if last_heartbeat_at is nil' do | ||
Jobs::ClockworkHeartbeat.any_instance.stubs(:last_heartbeat_at).returns(nil) | ||
subject.should be_false | ||
end | ||
|
||
it 'returns false if last_heartbeat_at is more than 2 minutes ago' do | ||
Jobs::ClockworkHeartbeat.any_instance.stubs(:last_heartbeat_at).returns(10.minutes.ago) | ||
subject.should be_false | ||
end | ||
|
||
it 'returns true if last_heartbeat_at is more recent than 2 minutes ago' do | ||
Jobs::ClockworkHeartbeat.any_instance.stubs(:last_heartbeat_at).returns(Time.zone.now) | ||
subject.should be_true | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters