clockwork_web 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clockwork_web might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +20 -6
- data/app/controllers/clockwork_web/home_controller.rb +3 -10
- data/app/helpers/clockwork_web/home_helper.rb +3 -3
- data/app/views/clockwork_web/home/index.html.erb +22 -3
- data/lib/clockwork_web.rb +75 -7
- data/lib/clockwork_web/engine.rb +1 -1
- data/lib/clockwork_web/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 925bad3f5186da79cd04a72e1aee6eac89341d9e
|
4
|
+
data.tar.gz: 7c141e2b984332b34e16f8ad947d72203468a31a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24497bfea53482d963022e171e0910cc21ce79f01ebc101a3265aac470fe25b7888e9d8237516b8eb5532e677c08ab141496a21277bdb6c1fe78880637f02925
|
7
|
+
data.tar.gz: da8ffb43b16dd28346b0e3aa099f440646a787da6b81b607921b8d95e52eeef86d002d76ee81e667fa82e0f8875f527af5ce99d773483b30082d2ed4e3e97e21
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# Clockwork Web
|
2
2
|
|
3
|
-
A web interface for
|
3
|
+
A web interface for Clockwork
|
4
|
+
|
5
|
+
[View the demo](https://clockwork-web.herokuapp.com/)
|
6
|
+
|
7
|
+
[screenshot goes here]
|
4
8
|
|
5
9
|
- see list of jobs
|
6
|
-
-
|
10
|
+
- monitor jobs
|
7
11
|
- disable jobs
|
8
12
|
|
9
|
-
Screenshot, demo, and better UI coming soon
|
10
|
-
|
11
13
|
## Installation
|
12
14
|
|
13
15
|
Add this line to your application’s Gemfile:
|
@@ -24,7 +26,7 @@ mount ClockworkWeb::Engine, at: "clockwork"
|
|
24
26
|
|
25
27
|
Be sure to secure the dashboard in production.
|
26
28
|
|
27
|
-
To see the last run and disable jobs, hook up Redis.
|
29
|
+
To see the last run and disable jobs, hook up Redis in an initializer.
|
28
30
|
|
29
31
|
```ruby
|
30
32
|
ClockworkWeb.redis = Redis.new
|
@@ -47,6 +49,13 @@ authenticate :user, lambda {|user| user.admin? } do
|
|
47
49
|
end
|
48
50
|
```
|
49
51
|
|
52
|
+
## Monitoring
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
ClockworkWeb.running?
|
56
|
+
ClockworkWeb.multiple?
|
57
|
+
```
|
58
|
+
|
50
59
|
## Customize
|
51
60
|
|
52
61
|
Change clock path
|
@@ -55,9 +64,14 @@ Change clock path
|
|
55
64
|
ClockworkWeb.clock_path = Rails.root.join("clock") # default
|
56
65
|
```
|
57
66
|
|
67
|
+
Turn off monitoring
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
ClockworkWeb.monitor = false
|
71
|
+
```
|
72
|
+
|
58
73
|
## TODO
|
59
74
|
|
60
|
-
- demo
|
61
75
|
- better design
|
62
76
|
|
63
77
|
## Contributing
|
@@ -17,16 +17,9 @@ module ClockworkWeb
|
|
17
17
|
]
|
18
18
|
end
|
19
19
|
|
20
|
-
@
|
21
|
-
@disabled =
|
22
|
-
|
23
|
-
keys = @events.flat_map{|e| ["clockwork:last_run:#{e.job}", "clockwork:disabled:#{e.job}"] }
|
24
|
-
values = ClockworkWeb.redis.mget(keys)
|
25
|
-
@events.each_with_index do |event, i|
|
26
|
-
@last_run[event.job] = values[i * 2]
|
27
|
-
@disabled[event.job] = values[i * 2 + 1]
|
28
|
-
end
|
29
|
-
end
|
20
|
+
@last_runs = ClockworkWeb.last_runs
|
21
|
+
@disabled = ClockworkWeb.disabled_jobs
|
22
|
+
@last_heartbeat = ClockworkWeb.last_heartbeat
|
30
23
|
end
|
31
24
|
|
32
25
|
def job
|
@@ -51,6 +51,25 @@
|
|
51
51
|
</head>
|
52
52
|
<body>
|
53
53
|
<div class="container">
|
54
|
+
<% if ClockworkWeb.redis %>
|
55
|
+
<% if ClockworkWeb.monitor %>
|
56
|
+
<% if ClockworkWeb.multiple? %>
|
57
|
+
<p>Multiple clockwork processes detected</p>
|
58
|
+
<% elsif ClockworkWeb.running? %>
|
59
|
+
<p>Clockwork is running</p>
|
60
|
+
<% else %>
|
61
|
+
<p>
|
62
|
+
Clockwork is not running
|
63
|
+
<% if @last_heartbeat %>
|
64
|
+
- last heartbeat was <%= time_ago_in_words(@last_heartbeat) %> ago
|
65
|
+
<% end %>
|
66
|
+
</p>
|
67
|
+
<% end %>
|
68
|
+
<% end %>
|
69
|
+
<% else %>
|
70
|
+
<p>Add Redis for monitoring and disabling jobs</p>
|
71
|
+
<% end %>
|
72
|
+
|
54
73
|
<table>
|
55
74
|
<thead>
|
56
75
|
<tr>
|
@@ -62,7 +81,7 @@
|
|
62
81
|
</thead>
|
63
82
|
<tbody>
|
64
83
|
<% @events.each do |event| %>
|
65
|
-
<% enabled = !@disabled
|
84
|
+
<% enabled = !@disabled.include?(event.job) %>
|
66
85
|
<tr class="<%= enabled ? "" : "disabled" %>">
|
67
86
|
<td><%= event.job %></td>
|
68
87
|
<td>
|
@@ -75,8 +94,8 @@
|
|
75
94
|
if __
|
76
95
|
<% end %>
|
77
96
|
</td>
|
78
|
-
<td><%= last_run(@
|
79
|
-
<td><%= button_to enabled ? "Disable" : "Enable", home_job_path(job: event.job, enable: !enabled) %></td>
|
97
|
+
<td><%= last_run(@last_runs[event.job]) %></td>
|
98
|
+
<td><%= button_to enabled ? "Disable" : "Enable", home_job_path(job: event.job, enable: !enabled), disabled: !ClockworkWeb.redis %></td>
|
80
99
|
</tr>
|
81
100
|
<% end %>
|
82
101
|
</tbody>
|
data/lib/clockwork_web.rb
CHANGED
@@ -8,14 +8,20 @@ require "robustly"
|
|
8
8
|
require "clockwork_web/engine"
|
9
9
|
|
10
10
|
module ClockworkWeb
|
11
|
+
LAST_RUNS_KEY = "clockwork:last_runs"
|
12
|
+
DISABLED_KEY = "clockwork:disabled"
|
13
|
+
HEARTBEAT_KEY = "clockwork:heartbeat"
|
14
|
+
|
11
15
|
class << self
|
12
16
|
attr_accessor :clock_path
|
13
17
|
attr_accessor :redis
|
18
|
+
attr_accessor :monitor
|
14
19
|
end
|
20
|
+
self.monitor = true
|
15
21
|
|
16
22
|
def self.enable(job)
|
17
23
|
if redis
|
18
|
-
redis.
|
24
|
+
redis.srem(DISABLED_KEY, job)
|
19
25
|
true
|
20
26
|
else
|
21
27
|
false
|
@@ -24,7 +30,7 @@ module ClockworkWeb
|
|
24
30
|
|
25
31
|
def self.disable(job)
|
26
32
|
if redis
|
27
|
-
redis.
|
33
|
+
redis.sadd(DISABLED_KEY, job)
|
28
34
|
true
|
29
35
|
else
|
30
36
|
false
|
@@ -33,20 +39,82 @@ module ClockworkWeb
|
|
33
39
|
|
34
40
|
def self.enabled?(job)
|
35
41
|
if redis
|
36
|
-
!redis.
|
42
|
+
!redis.sismember(DISABLED_KEY, job)
|
37
43
|
else
|
38
44
|
true
|
39
45
|
end
|
40
46
|
end
|
47
|
+
|
48
|
+
def self.disabled_jobs
|
49
|
+
if redis
|
50
|
+
Set.new(redis.smembers(DISABLED_KEY))
|
51
|
+
else
|
52
|
+
Set.new
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.last_runs
|
57
|
+
if redis
|
58
|
+
Hash[ redis.hgetall(LAST_RUNS_KEY).map{|job, timestamp| [job, Time.at(timestamp.to_i)] }.sort_by{|job, time| [time, job] } ]
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.set_last_run(job)
|
65
|
+
if redis
|
66
|
+
redis.hset(LAST_RUNS_KEY, job, Time.now.to_i)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.last_heartbeat
|
71
|
+
if redis
|
72
|
+
timestamp = redis.get(HEARTBEAT_KEY)
|
73
|
+
if timestamp
|
74
|
+
Time.at(timestamp.to_i)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.heartbeat
|
80
|
+
if redis
|
81
|
+
heartbeat = Time.now.to_i
|
82
|
+
if heartbeat % 10 == 0
|
83
|
+
prev_heartbeat = redis.getset(HEARTBEAT_KEY, heartbeat).to_i
|
84
|
+
if heartbeat == prev_heartbeat
|
85
|
+
# TODO debounce
|
86
|
+
# TODO try to surface hostnames when this condition is detected
|
87
|
+
# TODO hook to take action
|
88
|
+
redis.setex("clockwork:status", 20, "multiple")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.running?
|
95
|
+
last_heartbeat && last_heartbeat > 60.seconds.ago
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.multiple?
|
99
|
+
redis && redis.get("clockwork:status") == "multiple"
|
100
|
+
end
|
41
101
|
end
|
42
102
|
|
43
103
|
module Clockwork
|
44
|
-
on(:
|
104
|
+
on(:before_tick) do
|
105
|
+
ClockworkWeb.heartbeat if ClockworkWeb.monitor
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
on(:before_run) do |event, t|
|
45
110
|
run = true
|
46
111
|
safely do
|
47
|
-
run = ClockworkWeb.enabled?(
|
48
|
-
if run
|
49
|
-
ClockworkWeb.
|
112
|
+
run = ClockworkWeb.enabled?(event.job)
|
113
|
+
if run
|
114
|
+
ClockworkWeb.set_last_run(event.job)
|
115
|
+
else
|
116
|
+
manager.log "Skipping '#{event}'"
|
117
|
+
event.last = event.convert_timezone(t)
|
50
118
|
end
|
51
119
|
end
|
52
120
|
run
|
data/lib/clockwork_web/engine.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockwork_web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clockwork
|