module ClockworkWeb
Constants
- DISABLED_KEY
- HEARTBEAT_KEY
- LAST_RUNS_KEY
- STATUS_KEY
- VERSION
Attributes
clock_path[RW]
monitor[RW]
on_job_update[RW]
redis[RW]
running_threshold[RW]
Public Class Methods
disable(job)
click to toggle source
# File lib/clockwork_web.rb, line 34 def self.disable(job) if redis redis.sadd(DISABLED_KEY, job) true else false end end
disabled_jobs()
click to toggle source
# File lib/clockwork_web.rb, line 51 def self.disabled_jobs if redis Set.new(redis.smembers(DISABLED_KEY)) else Set.new end end
enable(job)
click to toggle source
# File lib/clockwork_web.rb, line 25 def self.enable(job) if redis redis.srem(DISABLED_KEY, job) true else false end end
enabled?(job)
click to toggle source
# File lib/clockwork_web.rb, line 43 def self.enabled?(job) if redis !redis.sismember(DISABLED_KEY, job) else true end end
heartbeat()
click to toggle source
# File lib/clockwork_web.rb, line 82 def self.heartbeat if redis heartbeat = Time.now.to_i if heartbeat % 10 == 0 prev_heartbeat = redis.getset(HEARTBEAT_KEY, heartbeat).to_i if prev_heartbeat >= heartbeat redis.setex(STATUS_KEY, 60, "multiple") end end end end
last_heartbeat()
click to toggle source
# File lib/clockwork_web.rb, line 73 def self.last_heartbeat if redis timestamp = redis.get(HEARTBEAT_KEY) if timestamp Time.at(timestamp.to_i) end end end
last_runs()
click to toggle source
# File lib/clockwork_web.rb, line 59 def self.last_runs if redis Hash[redis.hgetall(LAST_RUNS_KEY).map { |job, timestamp| [job, Time.at(timestamp.to_i)] }.sort_by { |job, time| [time, job] }] else {} end end
multiple?()
click to toggle source
# File lib/clockwork_web.rb, line 98 def self.multiple? redis && redis.get(STATUS_KEY) == "multiple" end
running?()
click to toggle source
# File lib/clockwork_web.rb, line 94 def self.running? last_heartbeat && last_heartbeat > Time.now - running_threshold end
set_last_run(job)
click to toggle source
# File lib/clockwork_web.rb, line 67 def self.set_last_run(job) if redis redis.hset(LAST_RUNS_KEY, job, Time.now.to_i) end end