loop_dance 0.4.6 → 0.5.3
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 +10 -9
- data/VERSION +1 -1
- data/lib/loop_dance/commands.rb +21 -15
- data/lib/loop_dance/task.rb +4 -2
- data/loop_dance.gemspec +3 -3
- data/spec/dancer_spec.rb +13 -14
- data/spec/task_spec.rb +2 -2
- metadata +33 -33
data/README.rdoc
CHANGED
@@ -10,7 +10,7 @@ One dancer is one daemon.
|
|
10
10
|
|
11
11
|
== Simple to setup
|
12
12
|
|
13
|
-
Create file 'lib/
|
13
|
+
Create file 'lib/dancers.rb':
|
14
14
|
|
15
15
|
class Dancer1 < LoopDance::Dancer
|
16
16
|
|
@@ -30,7 +30,7 @@ From the rails application:
|
|
30
30
|
|
31
31
|
Dancer1.start unless Dancer1.running?
|
32
32
|
|
33
|
-
By the rake tasks
|
33
|
+
By the rake tasks:
|
34
34
|
|
35
35
|
rake loop_dance:start_all
|
36
36
|
rake loop_dance:stop_all
|
@@ -44,17 +44,18 @@ By the rake tasks (TODO):
|
|
44
44
|
== Settings
|
45
45
|
|
46
46
|
class Dancer1 < LoopDance::Dancer
|
47
|
-
mute_log
|
48
|
-
|
47
|
+
mute_log true # mute redundant logging, just start, stop and errors
|
48
|
+
autostart true # enable autostart at rails server startup. False by default
|
49
49
|
|
50
50
|
# Don't trap signals. True by default (trapped)
|
51
|
-
|
51
|
+
trap_signals false
|
52
52
|
|
53
53
|
# daemon_controller`s options
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
start_timeout 60 # 15 by default
|
55
|
+
stop_timeout 60 # 15 by default
|
56
|
+
log_file_activity_timeout 17 # 7 by default
|
57
57
|
|
58
|
+
..
|
58
59
|
|
59
60
|
== Contributing to loop_dance
|
60
61
|
|
@@ -68,6 +69,6 @@ By the rake tasks (TODO):
|
|
68
69
|
|
69
70
|
== Copyright
|
70
71
|
|
71
|
-
Copyright (c) 2010 Danil Pismenny. See LICENSE.txt for
|
72
|
+
Copyright (c) 2010-2011 Danil Pismenny. See LICENSE.txt for
|
72
73
|
further details.
|
73
74
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.3
|
data/lib/loop_dance/commands.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
module LoopDance
|
2
2
|
|
3
3
|
module Commands
|
4
|
-
|
5
|
-
# # options
|
6
|
-
attr_accessor :muted_log, :autostart, :trap_signals,
|
7
|
-
:start_timeout, :stop_timeout, :log_file_activity_timeout
|
8
4
|
|
9
|
-
def
|
10
|
-
|
5
|
+
def self.super_attr_accessor(*syms)
|
6
|
+
attr_writer *syms
|
7
|
+
syms.each do |sym|
|
8
|
+
next if sym.is_a?(Hash)
|
9
|
+
class_eval "def #{sym} value = (nil;flag=true); if flag; return @#{sym}; else; @#{sym} = value; end ; end"
|
10
|
+
end
|
11
11
|
end
|
12
|
+
|
13
|
+
super_attr_accessor( :mute_log, :autostart, :trap_signals,
|
14
|
+
:start_timeout, :stop_timeout, :log_file_activity_timeout, :tasks )
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
|
17
|
+
attr_reader :timeout
|
18
|
+
|
16
19
|
|
17
|
-
def
|
18
|
-
|
20
|
+
def inherited(subclass)
|
21
|
+
subclass.trap_signals = true
|
19
22
|
end
|
20
23
|
|
21
24
|
def every( interval, &block )
|
22
25
|
@tasks = [] unless @tasks
|
23
|
-
@tasks << LoopDance::Task.new( interval, &block )
|
26
|
+
@tasks << LoopDance::Task.new( self, interval, &block )
|
24
27
|
find_minimal_timeout interval
|
25
28
|
@maximal_timeout = interval if !@maximal_timeout || @maximal_timeout < interval
|
26
29
|
end
|
@@ -32,6 +35,7 @@ module LoopDance
|
|
32
35
|
else
|
33
36
|
while (@run) do
|
34
37
|
@tasks.each_with_index do |task, index|
|
38
|
+
break unless @run
|
35
39
|
if task.time_to_run?
|
36
40
|
log "Run task ##{index} for every #{task.interval.inspect}"
|
37
41
|
task.run
|
@@ -45,7 +49,7 @@ module LoopDance
|
|
45
49
|
log "shutting down", true
|
46
50
|
end
|
47
51
|
|
48
|
-
def
|
52
|
+
def stop_me
|
49
53
|
@run = false
|
50
54
|
end
|
51
55
|
|
@@ -54,11 +58,11 @@ module LoopDance
|
|
54
58
|
end
|
55
59
|
|
56
60
|
def log(text, forced=false)
|
57
|
-
puts "#{Time.now} #{self}: #{text}" if forced || !
|
61
|
+
puts "#{Time.now} #{self}: #{text}" if forced || !mute_log
|
58
62
|
end
|
59
63
|
|
60
64
|
def print_status
|
61
|
-
puts "#{self}: timeout: #{
|
65
|
+
puts "#{self}: timeout: #{@timeout.inspect}, status: #{self.controller.running? ? 'running' : 'stopped'}\n"
|
62
66
|
if tasks.empty?
|
63
67
|
puts " no tasks defined"
|
64
68
|
else
|
@@ -70,6 +74,8 @@ module LoopDance
|
|
70
74
|
|
71
75
|
private
|
72
76
|
|
77
|
+
attr_accessor :run
|
78
|
+
|
73
79
|
def find_minimal_timeout( interval )
|
74
80
|
return @timeout = interval if @timeout.blank?
|
75
81
|
minimal = interval < @timeout ? interval : @timeout
|
data/lib/loop_dance/task.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
class LoopDance::Task
|
2
|
-
attr_accessor :last_run_at, :block, :interval
|
2
|
+
attr_accessor :last_run_at, :dancer, :block, :interval
|
3
3
|
|
4
|
-
def initialize( interval, &block )
|
4
|
+
def initialize( dancer, interval, &block )
|
5
5
|
run_count=0
|
6
|
+
self.dancer = dancer
|
6
7
|
self.interval = interval
|
7
8
|
self.block = block
|
8
9
|
|
@@ -18,6 +19,7 @@ class LoopDance::Task
|
|
18
19
|
block.call
|
19
20
|
rescue Exception => e
|
20
21
|
puts "Uncaught exception bubbled up: \n#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")} "
|
22
|
+
dancer.send(:stop_dancer)
|
21
23
|
ensure
|
22
24
|
self.last_run_at = Time.now
|
23
25
|
end
|
data/loop_dance.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{loop_dance}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Danil Pismenny"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-18}
|
13
13
|
s.description = %q{Really simple daemon builder and manager. Based on the looper and daemon_controller}
|
14
14
|
s.email = %q{danil@orionet.ru}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -78,7 +78,7 @@ Gem::Specification.new do |s|
|
|
78
78
|
s.homepage = %q{http://github.com/dapi/loop_dance}
|
79
79
|
s.licenses = ["MIT"]
|
80
80
|
s.require_paths = ["lib"]
|
81
|
-
s.rubygems_version = %q{1.
|
81
|
+
s.rubygems_version = %q{1.5.0}
|
82
82
|
s.summary = %q{Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup}
|
83
83
|
s.test_files = [
|
84
84
|
"spec/dancer_spec.rb",
|
data/spec/dancer_spec.rb
CHANGED
@@ -8,6 +8,7 @@ describe LoopDance do
|
|
8
8
|
|
9
9
|
before(:all) do
|
10
10
|
class Dancer1 < LoopDance::Dancer
|
11
|
+
start_timeout 60
|
11
12
|
every 2.seconds do
|
12
13
|
end
|
13
14
|
every 4.seconds do
|
@@ -21,14 +22,14 @@ describe LoopDance do
|
|
21
22
|
|
22
23
|
|
23
24
|
it { Dancer1.tasks.count.should == 4 }
|
24
|
-
it { Dancer1.
|
25
|
-
it { Dancer1.
|
25
|
+
it { Dancer1.start_timeout.should == 60 }
|
26
|
+
it { Dancer1.stop_timeout.should be_nil }
|
26
27
|
it { Dancer1.autostart.should be_false }
|
27
28
|
|
28
29
|
it { LoopDance::Dancer.tasks.should be_blank }
|
29
30
|
|
30
31
|
|
31
|
-
|
32
|
+
describe "another dancer not change first dancer's tasks" do
|
32
33
|
|
33
34
|
before(:all) do
|
34
35
|
class Dancer2 < LoopDance::Dancer
|
@@ -40,9 +41,7 @@ describe LoopDance do
|
|
40
41
|
end
|
41
42
|
|
42
43
|
it { Dancer2.tasks.count.should == 2 }
|
43
|
-
it { Dancer2.
|
44
|
-
it { Dancer2.maximal_timeout.should == 11 }
|
45
|
-
it { Dancer2.muted_log.should be_nil }
|
44
|
+
it { Dancer2.mute_log.should be_nil }
|
46
45
|
it { Dancer2.autostart.should be_false }
|
47
46
|
|
48
47
|
end
|
@@ -50,11 +49,11 @@ describe LoopDance do
|
|
50
49
|
describe "muting log and enabling autostart" do
|
51
50
|
before(:all) do
|
52
51
|
class Dancer1 < LoopDance::Dancer
|
53
|
-
mute_log
|
54
|
-
|
52
|
+
mute_log true
|
53
|
+
autostart true
|
55
54
|
end
|
56
55
|
end
|
57
|
-
it { Dancer1.
|
56
|
+
it { Dancer1.mute_log.should be_true }
|
58
57
|
it { Dancer1.autostart.should be_true }
|
59
58
|
end
|
60
59
|
|
@@ -71,26 +70,26 @@ describe LoopDance do
|
|
71
70
|
|
72
71
|
it { Dancer3.tasks.count.should == 2 }
|
73
72
|
it { Dancer3.timeout.should == 3 }
|
74
|
-
it { Dancer3.maximal_timeout.should == 9 }
|
75
73
|
|
76
74
|
end
|
77
75
|
|
78
|
-
describe "
|
76
|
+
describe "calculate minimal interval" do
|
79
77
|
|
80
78
|
before(:all) do
|
81
79
|
class Dancer < LoopDance::Dancer
|
80
|
+
mute_log true
|
82
81
|
every 2.seconds do
|
83
|
-
|
82
|
+
stop_me
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
87
|
it { Dancer.dance }
|
89
|
-
it { Dancer.
|
88
|
+
it { Dancer.send(:run).should be_false }
|
89
|
+
it { Dancer.timeout.should == 2 }
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
93
|
|
95
94
|
end
|
96
95
|
|
data/spec/task_spec.rb
CHANGED
@@ -4,12 +4,12 @@ describe LoopDance::Task do
|
|
4
4
|
|
5
5
|
describe "setup" do
|
6
6
|
|
7
|
-
|
8
7
|
let(:interval) { 60 }
|
8
|
+
let(:dancer) { LoopDance::Dancer }
|
9
9
|
|
10
10
|
before {
|
11
11
|
@result = 0
|
12
|
-
@task = LoopDance::Task.new interval do
|
12
|
+
@task = LoopDance::Task.new dancer, interval do
|
13
13
|
@result+=1
|
14
14
|
end
|
15
15
|
}
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 3
|
10
|
+
version: 0.5.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Danil Pismenny
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-18 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
name: activesupport
|
23
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -30,11 +30,11 @@ dependencies:
|
|
30
30
|
- 3
|
31
31
|
- 0
|
32
32
|
version: "3.0"
|
33
|
-
requirement: *id001
|
34
33
|
prerelease: false
|
35
|
-
name: activesupport
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
34
|
type: :runtime
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: i18n
|
38
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
@@ -44,11 +44,11 @@ dependencies:
|
|
44
44
|
segments:
|
45
45
|
- 0
|
46
46
|
version: "0"
|
47
|
-
requirement: *id002
|
48
47
|
prerelease: false
|
49
|
-
name: i18n
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
48
|
type: :runtime
|
49
|
+
requirement: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: daemon_controller
|
52
52
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
@@ -60,11 +60,11 @@ dependencies:
|
|
60
60
|
- 2
|
61
61
|
- 5
|
62
62
|
version: 0.2.5
|
63
|
-
requirement: *id003
|
64
63
|
prerelease: false
|
65
|
-
|
64
|
+
type: :runtime
|
65
|
+
requirement: *id003
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
|
-
|
67
|
+
name: bundler
|
68
68
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
70
70
|
requirements:
|
@@ -76,11 +76,11 @@ dependencies:
|
|
76
76
|
- 0
|
77
77
|
- 0
|
78
78
|
version: 1.0.0
|
79
|
-
requirement: *id004
|
80
79
|
prerelease: false
|
81
|
-
name: bundler
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
80
|
type: :development
|
81
|
+
requirement: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: jeweler
|
84
84
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
@@ -92,11 +92,11 @@ dependencies:
|
|
92
92
|
- 5
|
93
93
|
- 2
|
94
94
|
version: 1.5.2
|
95
|
-
requirement: *id005
|
96
95
|
prerelease: false
|
97
|
-
name: jeweler
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
96
|
type: :development
|
97
|
+
requirement: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rcov
|
100
100
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
101
101
|
none: false
|
102
102
|
requirements:
|
@@ -106,11 +106,11 @@ dependencies:
|
|
106
106
|
segments:
|
107
107
|
- 0
|
108
108
|
version: "0"
|
109
|
-
requirement: *id006
|
110
109
|
prerelease: false
|
111
|
-
name: rcov
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
110
|
type: :development
|
111
|
+
requirement: *id006
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: ruby-debug
|
114
114
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
115
115
|
none: false
|
116
116
|
requirements:
|
@@ -120,11 +120,11 @@ dependencies:
|
|
120
120
|
segments:
|
121
121
|
- 0
|
122
122
|
version: "0"
|
123
|
-
requirement: *id007
|
124
123
|
prerelease: false
|
125
|
-
name: ruby-debug
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
124
|
type: :development
|
125
|
+
requirement: *id007
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
128
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
@@ -134,11 +134,11 @@ dependencies:
|
|
134
134
|
segments:
|
135
135
|
- 0
|
136
136
|
version: "0"
|
137
|
-
requirement: *id008
|
138
137
|
prerelease: false
|
139
|
-
name: rspec
|
140
|
-
- !ruby/object:Gem::Dependency
|
141
138
|
type: :development
|
139
|
+
requirement: *id008
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: shoulda
|
142
142
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
143
143
|
none: false
|
144
144
|
requirements:
|
@@ -148,9 +148,9 @@ dependencies:
|
|
148
148
|
segments:
|
149
149
|
- 0
|
150
150
|
version: "0"
|
151
|
-
requirement: *id009
|
152
151
|
prerelease: false
|
153
|
-
|
152
|
+
type: :development
|
153
|
+
requirement: *id009
|
154
154
|
description: Really simple daemon builder and manager. Based on the looper and daemon_controller
|
155
155
|
email: danil@orionet.ru
|
156
156
|
executables: []
|
@@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
requirements: []
|
249
249
|
|
250
250
|
rubyforge_project:
|
251
|
-
rubygems_version: 1.
|
251
|
+
rubygems_version: 1.5.0
|
252
252
|
signing_key:
|
253
253
|
specification_version: 3
|
254
254
|
summary: Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup
|