clockwork_web 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of clockwork_web might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/app/controllers/clockwork_web/home_controller.rb +21 -2
- data/app/helpers/clockwork_web/home_helper.rb +13 -9
- data/app/views/clockwork_web/home/index.html.erb +6 -8
- data/lib/clockwork_web.rb +21 -10
- data/lib/clockwork_web/engine.rb +2 -1
- data/lib/clockwork_web/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7c3867ecea98c7c51988649055e143e26ba30e4
|
4
|
+
data.tar.gz: 14e364f74e9f89798dd7a399bf7d78fee1f40cc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db09daf6bff8cc75ce2829a9501a32c60ed4951ea7b6a54c2a0ca443b195fe738464b8a4ecfcaef0da75ea40390d4c2b5946644660e365b45dc947326d39970e
|
7
|
+
data.tar.gz: 7423110942b760aa63b881a455a1cec2884c9acbb7a097023f32233ba1914d536179b13636f7a236653e243acc9b36de29e1aa01950ff42b1f0d5110c3887cf3
|
data/README.md
CHANGED
@@ -6,8 +6,27 @@ module ClockworkWeb
|
|
6
6
|
http_basic_authenticate_with name: ENV["CLOCKWORK_USERNAME"], password: ENV["CLOCKWORK_PASSWORD"] if ENV["CLOCKWORK_PASSWORD"]
|
7
7
|
|
8
8
|
def index
|
9
|
-
@events =
|
10
|
-
|
9
|
+
@events =
|
10
|
+
Clockwork.manager.instance_variable_get(:@events).sort_by do |e|
|
11
|
+
at = e.instance_variable_get(:@at)
|
12
|
+
[
|
13
|
+
e.instance_variable_get(:@period),
|
14
|
+
(at && at.instance_variable_get(:@hour)) || -1,
|
15
|
+
(at && at.instance_variable_get(:@min)) || -1,
|
16
|
+
e.job.to_s
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
@last_run = {}
|
21
|
+
@disabled = {}
|
22
|
+
if ClockworkWeb.redis
|
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
|
11
30
|
end
|
12
31
|
|
13
32
|
def job
|
@@ -3,9 +3,9 @@ module ClockworkWeb
|
|
3
3
|
|
4
4
|
def friendly_period(period)
|
5
5
|
if period % 1.day == 0
|
6
|
-
|
6
|
+
pluralize(period / 1.day, "day")
|
7
7
|
elsif period % 1.hour == 0
|
8
|
-
|
8
|
+
pluralize(period / 1.hour, "hour")
|
9
9
|
elsif period % 1.minute == 0
|
10
10
|
"#{period / 1.minute} min"
|
11
11
|
else
|
@@ -13,13 +13,17 @@ module ClockworkWeb
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def last_run(
|
17
|
-
if
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def last_run(timestamp)
|
17
|
+
if timestamp
|
18
|
+
time_ago_in_words(Time.at(timestamp.to_i))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def friendly_time_part(time_part)
|
23
|
+
if time_part
|
24
|
+
time_part.to_s.rjust(2, "0")
|
25
|
+
else
|
26
|
+
"**"
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -62,22 +62,20 @@
|
|
62
62
|
</thead>
|
63
63
|
<tbody>
|
64
64
|
<% @events.each do |event| %>
|
65
|
-
<% enabled =
|
65
|
+
<% enabled = !@disabled[event.job] %>
|
66
66
|
<tr class="<%= enabled ? "" : "disabled" %>">
|
67
67
|
<td><%= event.job %></td>
|
68
68
|
<td>
|
69
69
|
<%= friendly_period(event.instance_variable_get(:@period)) %>
|
70
70
|
<% at = event.instance_variable_get(:@at) %>
|
71
71
|
<% if at %>
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
wday: <%= at.instance_variable_get(:@wday) %>
|
77
|
-
</div>
|
72
|
+
at <%= friendly_time_part(at.instance_variable_get(:@hour)) %>:<%= friendly_time_part(at.instance_variable_get(:@min)) %>
|
73
|
+
<% end %>
|
74
|
+
<% if event.instance_variable_get(:@if) %>
|
75
|
+
if __
|
78
76
|
<% end %>
|
79
77
|
</td>
|
80
|
-
<td><%= last_run(event) %></td>
|
78
|
+
<td><%= last_run(@last_run[event.job]) %></td>
|
81
79
|
<td><%= button_to enabled ? "Disable" : "Enable", home_job_path(job: event.job, enable: !enabled) %></td>
|
82
80
|
</tr>
|
83
81
|
<% end %>
|
data/lib/clockwork_web.rb
CHANGED
@@ -9,21 +9,34 @@ require "clockwork_web/engine"
|
|
9
9
|
|
10
10
|
module ClockworkWeb
|
11
11
|
class << self
|
12
|
+
attr_accessor :clock_path
|
12
13
|
attr_accessor :redis
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.enable(job)
|
16
|
-
|
17
|
-
|
17
|
+
if redis
|
18
|
+
redis.del("clockwork:disabled:#{job}")
|
19
|
+
true
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
def self.disable(job)
|
21
|
-
|
22
|
-
|
26
|
+
if redis
|
27
|
+
redis.set("clockwork:disabled:#{job}", 1)
|
28
|
+
true
|
29
|
+
else
|
30
|
+
false
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
def self.enabled?(job)
|
26
|
-
|
35
|
+
if redis
|
36
|
+
!redis.exists("clockwork:disabled:#{job}")
|
37
|
+
else
|
38
|
+
true
|
39
|
+
end
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
@@ -31,11 +44,9 @@ module Clockwork
|
|
31
44
|
on(:before_run) do |t|
|
32
45
|
run = true
|
33
46
|
safely do
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
ClockworkWeb.redis.set("clockwork:last_run:#{t.job}", Time.now.to_i)
|
38
|
-
end
|
47
|
+
run = ClockworkWeb.enabled?(t.job)
|
48
|
+
if run && ClockworkWeb.redis
|
49
|
+
ClockworkWeb.redis.set("clockwork:last_run:#{t.job}", Time.now.to_i)
|
39
50
|
end
|
40
51
|
end
|
41
52
|
run
|
data/lib/clockwork_web/engine.rb
CHANGED