loop_dance 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  gem "activesupport", ">= 3.0"
5
5
  gem "i18n"
6
- gem "daemon_controller"
6
+ gem "daemon_controller", ">= 0.2.5"
7
7
 
8
8
  # Add dependencies to develop your gem here.
9
9
  # Include everything needed to run rake, tests, features, etc.
data/Rakefile CHANGED
@@ -15,14 +15,19 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "loop_dance"
16
16
  gem.homepage = "http://github.com/dapi/loop_dance"
17
17
  gem.license = "MIT"
18
- gem.summary = %Q{Simple auto-starting daemon based on the looper and daemon_controller}
19
- gem.description = %Q{Really easy setup. Auto-start daaemon at rails server startup. Rake's tasks based control.} # ' anti ruby-mode
18
+ gem.summary = %Q{Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup} # ' anti ruby-mode
19
+ # Simple scheduler daemon. It's managed from ruby application or by rake tasks
20
+ gem.description = %Q{Really simple daemon builder and manager. Based on the looper and daemon_controller}
20
21
  gem.email = "danil@orionet.ru"
21
22
  gem.authors = ["Danil Pismenny"]
22
23
  # Include your dependencies below. Runtime dependencies are required when using your gem,
23
24
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
25
  gem.add_runtime_dependency 'daemon_controller', '>= 0.2.5'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_runtime_dependency 'active_support', '>= 3.0'
27
+ gem.add_runtime_dependency 'i18n'
28
+ gem.add_development_dependency 'rspec'
29
+ gem.add_development_dependency 'jeweler'
30
+ gem.add_development_dependency 'shoulda'
26
31
  end
27
32
  Jeweler::RubygemsDotOrgTasks.new
28
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.2
@@ -42,6 +42,17 @@ module LoopDance
42
42
  def log(text)
43
43
  puts "#{Time.now} #{self}: #{text}"
44
44
  end
45
+
46
+ def print_status
47
+ puts "#{self}: timeout: #{self.timeout.inspect}, status: #{self.controller.running? ? 'running' : 'stopped'}\n"
48
+ if tasks.empty?
49
+ puts " no tasks defined"
50
+ else
51
+ tasks.each_with_index do |task,index|
52
+ puts " Task ##{index} runs every #{task.interval.inspect}"
53
+ end
54
+ end
55
+ end
45
56
 
46
57
  private
47
58
 
@@ -38,18 +38,35 @@ module LoopDance
38
38
  end
39
39
  end
40
40
 
41
- def auto_start
41
+ def safely_start
42
42
  dancer.log "Starting.. (#{@start_command})"
43
- start unless running?
43
+ if running?
44
+ dancer.log "Dancer is already running"
45
+ else
46
+ start
47
+ dancer.log "Started"
48
+ end
44
49
  rescue => exception # DaemonController::StartTimeout
45
- dancer.log "Exception until starting #{dancer}: #{exception.inspect}"
46
- dancer.log exception.backtrace if defined?( Rails ) && !Rails.env.production?
50
+ log_exception exception
47
51
  end
48
-
49
-
52
+
53
+ def safely_stop
54
+ dancer.log "Stopping.."
55
+ stop if running?
56
+ rescue => exception # DaemonController::StartTimeout
57
+ log_exception exception
58
+ end
59
+
50
60
  #stop
51
61
  #start
52
62
  #running
63
+
64
+ private
65
+
66
+ def log_exception( exception )
67
+ dancer.log "Exception until stopping #{dancer}: #{exception.inspect}"
68
+ dancer.log exception.backtrace if defined?( Rails ) && !Rails.env.production?
69
+ end
53
70
 
54
71
  end
55
72
  end
@@ -4,13 +4,11 @@ module LoopDance
4
4
 
5
5
  autoload :Commands, 'loop_dance/commands'
6
6
  autoload :Controller, 'loop_dance/controller'
7
-
7
+
8
8
  class Dancer
9
9
 
10
-
11
10
  extend LoopDance::Commands
12
11
 
13
-
14
12
  class << self
15
13
 
16
14
  # Can start daemon automatically at rails server startup? true by default
@@ -2,25 +2,26 @@ require 'rails'
2
2
  module LoopDance
3
3
 
4
4
  class Railtie < Rails::Railtie
5
-
6
- initializer 'loop_dance.initialize', :after => :after_initialize do
7
5
 
8
- load_dancers
9
- # Do not start dancers if rake or other tasks
10
- LoopDance.auto_start if server_startup?
6
+ def self.load_dancers
7
+ require 'dancers'
11
8
  end
12
9
 
13
- def load_dancers
14
- require 'dancers'
10
+ initializer 'loop_dance.initialize' do
11
+ self.class.load_dancers
12
+ # Do not start dancers if rake or other tasks
13
+ LoopDance.start_all if server_startup?
15
14
  end
16
15
 
16
+
17
17
  # FIX: Is there more cute solution?
18
18
  def server_startup?
19
19
  caller.to_s=~/config\.ru/
20
20
  end
21
21
 
22
22
  rake_tasks do
23
- #load "path/to/my_railtie.tasks"
23
+ load_dancers
24
+ load File.expand_path('../../../tasks/loop_dance.rake', __FILE__)
24
25
  end
25
26
 
26
27
  end
data/lib/loop_dance.rb CHANGED
@@ -3,17 +3,24 @@ module LoopDance
3
3
  autoload :Task, "loop_dance/task"
4
4
  autoload :Dancer, "loop_dance/dancer"
5
5
 
6
- def self.auto_start
7
- return puts "LoopDance: No dancers to start" if LoopDance::Dancer.subclasses.empty?
8
- LoopDance::Dancer.subclasses.each do |dancer|
9
- dancer.controller.auto_start if dancer.start_automatic
6
+ class << self
7
+
8
+ def start_all( force=false )
9
+ return puts "LoopDance: No dancers defined" if LoopDance::Dancer.subclasses.empty?
10
+ LoopDance::Dancer.subclasses.each do |dancer|
11
+ dancer.controller.safely_start if force || dancer.start_automatic
12
+ end
10
13
  end
14
+
15
+ def stop_all
16
+ return puts "LoopDance: No dancers defined" if LoopDance::Dancer.subclasses.empty?
17
+ LoopDance::Dancer.subclasses.each do |dancer|
18
+ dancer.controller.safely_stop
19
+ end
20
+ end
21
+
11
22
  end
12
23
 
13
24
  end
14
25
 
15
- begin
16
- require 'loop_dance/railtie'
17
- rescue LoadError => e
18
- puts "Can't load loop_dance/railtie"
19
- end
26
+ require 'loop_dance/railtie' if defined? Rails
data/loop_dance.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{loop_dance}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.2"
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
12
  s.date = %q{2011-01-01}
13
- s.description = %q{Really easy setup. Auto-start daaemon at rails server startup. Rake's tasks based control.}
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 = [
16
16
  "LICENSE.txt",
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "spec/dancer_spec.rb",
36
36
  "spec/spec_helper.rb",
37
37
  "spec/task_spec.rb",
38
+ "tasks/loop_dance.rake",
38
39
  "test/rails/.gitignore",
39
40
  "test/rails/Gemfile",
40
41
  "test/rails/Rakefile",
@@ -77,7 +78,7 @@ Gem::Specification.new do |s|
77
78
  s.licenses = ["MIT"]
78
79
  s.require_paths = ["lib"]
79
80
  s.rubygems_version = %q{1.3.7}
80
- s.summary = %q{Simple auto-starting daemon based on the looper and daemon_controller}
81
+ s.summary = %q{Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup}
81
82
  s.test_files = [
82
83
  "spec/dancer_spec.rb",
83
84
  "spec/spec_helper.rb",
@@ -106,7 +107,7 @@ Gem::Specification.new do |s|
106
107
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
107
108
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0"])
108
109
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
109
- s.add_runtime_dependency(%q<daemon_controller>, [">= 0"])
110
+ s.add_runtime_dependency(%q<daemon_controller>, [">= 0.2.5"])
110
111
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
111
112
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
112
113
  s.add_development_dependency(%q<rcov>, [">= 0"])
@@ -114,10 +115,15 @@ Gem::Specification.new do |s|
114
115
  s.add_development_dependency(%q<rspec>, [">= 0"])
115
116
  s.add_development_dependency(%q<shoulda>, [">= 0"])
116
117
  s.add_runtime_dependency(%q<daemon_controller>, [">= 0.2.5"])
118
+ s.add_runtime_dependency(%q<active_support>, [">= 3.0"])
119
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
120
+ s.add_development_dependency(%q<rspec>, [">= 0"])
121
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
122
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
117
123
  else
118
124
  s.add_dependency(%q<activesupport>, [">= 3.0"])
119
125
  s.add_dependency(%q<i18n>, [">= 0"])
120
- s.add_dependency(%q<daemon_controller>, [">= 0"])
126
+ s.add_dependency(%q<daemon_controller>, [">= 0.2.5"])
121
127
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
122
128
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
123
129
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -125,11 +131,16 @@ Gem::Specification.new do |s|
125
131
  s.add_dependency(%q<rspec>, [">= 0"])
126
132
  s.add_dependency(%q<shoulda>, [">= 0"])
127
133
  s.add_dependency(%q<daemon_controller>, [">= 0.2.5"])
134
+ s.add_dependency(%q<active_support>, [">= 3.0"])
135
+ s.add_dependency(%q<i18n>, [">= 0"])
136
+ s.add_dependency(%q<rspec>, [">= 0"])
137
+ s.add_dependency(%q<jeweler>, [">= 0"])
138
+ s.add_dependency(%q<shoulda>, [">= 0"])
128
139
  end
129
140
  else
130
141
  s.add_dependency(%q<activesupport>, [">= 3.0"])
131
142
  s.add_dependency(%q<i18n>, [">= 0"])
132
- s.add_dependency(%q<daemon_controller>, [">= 0"])
143
+ s.add_dependency(%q<daemon_controller>, [">= 0.2.5"])
133
144
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
134
145
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
135
146
  s.add_dependency(%q<rcov>, [">= 0"])
@@ -137,6 +148,11 @@ Gem::Specification.new do |s|
137
148
  s.add_dependency(%q<rspec>, [">= 0"])
138
149
  s.add_dependency(%q<shoulda>, [">= 0"])
139
150
  s.add_dependency(%q<daemon_controller>, [">= 0.2.5"])
151
+ s.add_dependency(%q<active_support>, [">= 3.0"])
152
+ s.add_dependency(%q<i18n>, [">= 0"])
153
+ s.add_dependency(%q<rspec>, [">= 0"])
154
+ s.add_dependency(%q<jeweler>, [">= 0"])
155
+ s.add_dependency(%q<shoulda>, [">= 0"])
140
156
  end
141
157
  end
142
158
 
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ #require 'watchdog'
4
+
5
+ namespace :loop_dance do
6
+
7
+ task :loop_dance => :environment do
8
+ end
9
+
10
+ desc "Start (or restart) all dancers"
11
+ task :start_all => :loop_dance do
12
+ LoopDance.start_all
13
+ end
14
+
15
+ desc "Stop all dancers"
16
+ task :stop_all => :loop_dance do
17
+ LoopDance.stop_all
18
+ end
19
+
20
+ desc "Status of all dancers"
21
+ task :status => :loop_dance do
22
+ return puts "LoopDance: No dancers defined" if LoopDance::Dancer.subclasses.empty?
23
+ LoopDance::Dancer.subclasses.each do |dancer|
24
+ dancer.print_status
25
+ end
26
+ end
27
+
28
+ LoopDance::Dancer.subclasses.each do |dancer|
29
+
30
+ namespace dancer.name.underscore.to_sym do
31
+
32
+ desc "Start (or restart) all #{dancer}"
33
+ task :start => :loop_dance do
34
+ dancer.controller.safely_start
35
+ end
36
+
37
+ desc "Stop #{dancer}"
38
+ task :stop => :loop_dance do
39
+ dancer.controller.safely_stop
40
+ end
41
+
42
+ desc "Status of #{dancer}"
43
+ task :status => :loop_dance do
44
+ dancer.print_status
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+
data/test/rails/Gemfile CHANGED
@@ -11,6 +11,10 @@ gem "ruby-debug"
11
11
 
12
12
  gem 'sqlite3-ruby', :require => 'sqlite3'
13
13
 
14
+ gem 'gtk2'
15
+ gem "ruby-libnotify"
16
+ gem 'slowgrowl'
17
+
14
18
  # Use unicorn as the web server
15
19
  # gem 'unicorn'
16
20
 
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: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Danil Pismenny
@@ -55,10 +55,12 @@ dependencies:
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- hash: 3
58
+ hash: 29
59
59
  segments:
60
60
  - 0
61
- version: "0"
61
+ - 2
62
+ - 5
63
+ version: 0.2.5
62
64
  requirement: *id003
63
65
  type: :runtime
64
66
  - !ruby/object:Gem::Dependency
@@ -165,7 +167,78 @@ dependencies:
165
167
  version: 0.2.5
166
168
  requirement: *id010
167
169
  type: :runtime
168
- description: Really easy setup. Auto-start daaemon at rails server startup. Rake's tasks based control.
170
+ - !ruby/object:Gem::Dependency
171
+ prerelease: false
172
+ name: active_support
173
+ version_requirements: &id011 !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ hash: 7
179
+ segments:
180
+ - 3
181
+ - 0
182
+ version: "3.0"
183
+ requirement: *id011
184
+ type: :runtime
185
+ - !ruby/object:Gem::Dependency
186
+ prerelease: false
187
+ name: i18n
188
+ version_requirements: &id012 !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ hash: 3
194
+ segments:
195
+ - 0
196
+ version: "0"
197
+ requirement: *id012
198
+ type: :runtime
199
+ - !ruby/object:Gem::Dependency
200
+ prerelease: false
201
+ name: rspec
202
+ version_requirements: &id013 !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ hash: 3
208
+ segments:
209
+ - 0
210
+ version: "0"
211
+ requirement: *id013
212
+ type: :development
213
+ - !ruby/object:Gem::Dependency
214
+ prerelease: false
215
+ name: jeweler
216
+ version_requirements: &id014 !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ hash: 3
222
+ segments:
223
+ - 0
224
+ version: "0"
225
+ requirement: *id014
226
+ type: :development
227
+ - !ruby/object:Gem::Dependency
228
+ prerelease: false
229
+ name: shoulda
230
+ version_requirements: &id015 !ruby/object:Gem::Requirement
231
+ none: false
232
+ requirements:
233
+ - - ">="
234
+ - !ruby/object:Gem::Version
235
+ hash: 3
236
+ segments:
237
+ - 0
238
+ version: "0"
239
+ requirement: *id015
240
+ type: :development
241
+ description: Really simple daemon builder and manager. Based on the looper and daemon_controller
169
242
  email: danil@orionet.ru
170
243
  executables: []
171
244
 
@@ -193,6 +266,7 @@ files:
193
266
  - spec/dancer_spec.rb
194
267
  - spec/spec_helper.rb
195
268
  - spec/task_spec.rb
269
+ - tasks/loop_dance.rake
196
270
  - test/rails/.gitignore
197
271
  - test/rails/Gemfile
198
272
  - test/rails/Rakefile
@@ -263,7 +337,7 @@ rubyforge_project:
263
337
  rubygems_version: 1.3.7
264
338
  signing_key:
265
339
  specification_version: 3
266
- summary: Simple auto-starting daemon based on the looper and daemon_controller
340
+ summary: Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup
267
341
  test_files:
268
342
  - spec/dancer_spec.rb
269
343
  - spec/spec_helper.rb