Module: ClockworkWeb
- Defined in:
- lib/clockwork_web.rb,
lib/clockwork_web/engine.rb,
lib/clockwork_web/version.rb,
app/helpers/clockwork_web/home_helper.rb,
app/controllers/clockwork_web/home_controller.rb
Defined Under Namespace
Modules: HomeHelper
Classes: Engine, HomeController
Constant Summary
collapse
- LAST_RUNS_KEY =
"clockwork:last_runs"
- DISABLED_KEY =
"clockwork:disabled"
- HEARTBEAT_KEY =
"clockwork:heartbeat"
- STATUS_KEY =
"clockwork:status"
- VERSION =
"0.3.1"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.clock_path ⇒ Object
Returns the value of attribute clock_path.
16
17
18
|
# File 'lib/clockwork_web.rb', line 16
def clock_path
@clock_path
end
|
.monitor ⇒ Object
Returns the value of attribute monitor.
18
19
20
|
# File 'lib/clockwork_web.rb', line 18
def monitor
@monitor
end
|
.on_job_update ⇒ Object
Returns the value of attribute on_job_update.
20
21
22
|
# File 'lib/clockwork_web.rb', line 20
def on_job_update
@on_job_update
end
|
.redis ⇒ Object
Returns the value of attribute redis.
17
18
19
|
# File 'lib/clockwork_web.rb', line 17
def redis
@redis
end
|
.running_threshold ⇒ Object
Returns the value of attribute running_threshold.
19
20
21
|
# File 'lib/clockwork_web.rb', line 19
def running_threshold
@running_threshold
end
|
Class Method Details
.disable(job) ⇒ Object
34
35
36
37
38
39
40
41
|
# 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 ⇒ Object
51
52
53
54
55
56
57
|
# 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) ⇒ Object
25
26
27
28
29
30
31
32
|
# 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) ⇒ Boolean
43
44
45
46
47
48
49
|
# File 'lib/clockwork_web.rb', line 43
def self.enabled?(job)
if redis
!redis.sismember(DISABLED_KEY, job)
else
true
end
end
|
.heartbeat ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# 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 ⇒ Object
73
74
75
76
77
78
79
80
|
# 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 ⇒ Object
59
60
61
62
63
64
65
|
# 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? ⇒ Boolean
98
99
100
|
# File 'lib/clockwork_web.rb', line 98
def self.multiple?
redis && redis.get(STATUS_KEY) == "multiple"
end
|
.running? ⇒ Boolean
94
95
96
|
# File 'lib/clockwork_web.rb', line 94
def self.running?
last_heartbeat && last_heartbeat > Time.now - running_threshold
end
|
.set_last_run(job) ⇒ Object
67
68
69
70
71
|
# 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
|