loop_dance 0.2.5 → 0.3.1
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.
- data/README.rdoc +8 -0
- data/VERSION +1 -1
- data/lib/loop_dance/commands.rb +19 -8
- data/lib/loop_dance/controller.rb +2 -6
- data/lib/loop_dance/dancer.rb +0 -2
- data/lib/loop_dance.rb +1 -1
- data/loop_dance.gemspec +1 -1
- data/spec/dancer_spec.rb +13 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -41,6 +41,14 @@ By the rake tasks (TODO):
|
|
41
41
|
rake loop_dance:dancer1:stop
|
42
42
|
rake loop_dance:dancer1:status
|
43
43
|
|
44
|
+
|
45
|
+
== Settings
|
46
|
+
|
47
|
+
class Dancer1 < LoopDance::Dancer
|
48
|
+
mute_log # mute redundant logging, just start, stop and errors
|
49
|
+
disable_autostart # disable autostart at rails server startup
|
50
|
+
|
51
|
+
|
44
52
|
== Contributing to loop_dance
|
45
53
|
|
46
54
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.1
|
data/lib/loop_dance/commands.rb
CHANGED
@@ -2,8 +2,19 @@ module LoopDance
|
|
2
2
|
|
3
3
|
module Commands
|
4
4
|
|
5
|
-
attr_accessor :tasks, :timeout, :maximal_timeout
|
6
|
-
|
5
|
+
attr_accessor :tasks, :timeout, :maximal_timeout, :muted_log, :autostart
|
6
|
+
|
7
|
+
@autostart = true
|
8
|
+
|
9
|
+
def mute_log
|
10
|
+
@muted_log = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def disable_autostart
|
14
|
+
@autostart = false
|
15
|
+
end
|
16
|
+
|
17
|
+
|
7
18
|
def every( interval, &block )
|
8
19
|
@tasks = [] unless @tasks
|
9
20
|
@tasks << LoopDance::Task.new( interval, &block )
|
@@ -14,7 +25,7 @@ module LoopDance
|
|
14
25
|
def dance
|
15
26
|
loop_init
|
16
27
|
if @tasks.empty?
|
17
|
-
log "No tasks defined."
|
28
|
+
log "No tasks defined.", true
|
18
29
|
else
|
19
30
|
while (@run) do
|
20
31
|
@tasks.each_with_index do |task, index|
|
@@ -28,7 +39,7 @@ module LoopDance
|
|
28
39
|
sleep @timeout.to_i if @run
|
29
40
|
end
|
30
41
|
end
|
31
|
-
log "shutting down"
|
42
|
+
log "shutting down", true
|
32
43
|
end
|
33
44
|
|
34
45
|
def stop
|
@@ -39,8 +50,8 @@ module LoopDance
|
|
39
50
|
"log/#{name.underscore}.pid"
|
40
51
|
end
|
41
52
|
|
42
|
-
def log(text)
|
43
|
-
puts "#{Time.now} #{self}: #{text}"
|
53
|
+
def log(text, forced=false)
|
54
|
+
puts "#{Time.now} #{self}: #{text}" if forced || !muted_log
|
44
55
|
end
|
45
56
|
|
46
57
|
def print_status
|
@@ -75,7 +86,7 @@ module LoopDance
|
|
75
86
|
|
76
87
|
def trap_signals
|
77
88
|
sigtrap = proc {
|
78
|
-
log "caught trapped signal, shutting down"
|
89
|
+
log "caught trapped signal, shutting down", true
|
79
90
|
@run = false
|
80
91
|
}
|
81
92
|
["SIGTERM", "SIGINT", "SIGHUP"].each do |signal|
|
@@ -89,7 +100,7 @@ module LoopDance
|
|
89
100
|
write_pid
|
90
101
|
trap_signals
|
91
102
|
@run = true
|
92
|
-
log "Process started and sleep for #{timeout.inspect}. kill #{Process.pid} to stop"
|
103
|
+
log "Process started and sleep for #{timeout.inspect}. kill #{Process.pid} to stop", true
|
93
104
|
end
|
94
105
|
|
95
106
|
def write_pid
|
@@ -3,9 +3,7 @@ require 'daemon_controller'
|
|
3
3
|
module LoopDance
|
4
4
|
class Controller < DaemonController
|
5
5
|
|
6
|
-
cattr_accessor :dancer
|
7
|
-
|
8
|
-
self.start_timeout = 45
|
6
|
+
cattr_accessor :dancer
|
9
7
|
|
10
8
|
class << self
|
11
9
|
|
@@ -17,9 +15,7 @@ module LoopDance
|
|
17
15
|
:start_command => start_command,
|
18
16
|
:ping_command => lambda { true },
|
19
17
|
:pid_file => dancer.pid_file,
|
20
|
-
:log_file => log_file
|
21
|
-
:start_timeout => start_timeout,
|
22
|
-
:log_file_activity_timeout => dancer.maximal_timeout + 3 # 3 seconds to stock
|
18
|
+
:log_file => log_file
|
23
19
|
}
|
24
20
|
super h
|
25
21
|
end
|
data/lib/loop_dance/dancer.rb
CHANGED
data/lib/loop_dance.rb
CHANGED
@@ -8,7 +8,7 @@ module LoopDance
|
|
8
8
|
def start_all( force=false )
|
9
9
|
return puts "LoopDance: No dancers defined" if LoopDance::Dancer.subclasses.empty?
|
10
10
|
LoopDance::Dancer.subclasses.each do |dancer|
|
11
|
-
dancer.controller.safely_start if force || dancer.
|
11
|
+
dancer.controller.safely_start if force || dancer.autostart
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
data/loop_dance.gemspec
CHANGED
data/spec/dancer_spec.rb
CHANGED
@@ -43,9 +43,22 @@ describe LoopDance do
|
|
43
43
|
it { Dancer2.tasks.count.should == 2 }
|
44
44
|
it { Dancer2.timeout.should == 1 }
|
45
45
|
it { Dancer2.maximal_timeout.should == 11 }
|
46
|
+
it { Dancer2.muted_log.should be_nil }
|
47
|
+
it { Dancer1.autostart.should be_true }
|
46
48
|
|
47
49
|
end
|
48
50
|
|
51
|
+
describe "muting log and disabling autostart" do
|
52
|
+
before(:all) do
|
53
|
+
class Dancer1 < LoopDance::Dancer
|
54
|
+
mute_log
|
55
|
+
disable_autostart
|
56
|
+
end
|
57
|
+
end
|
58
|
+
it { Dancer1.muted_log.should be_true }
|
59
|
+
it { Dancer1.autostart.should be_false }
|
60
|
+
end
|
61
|
+
|
49
62
|
describe "find right minimal timeout" do
|
50
63
|
|
51
64
|
before(:all) do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loop_dance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Danil Pismenny
|