loop_dance 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,7 +1,8 @@
1
1
  = LoopDance
2
2
 
3
- No forks. No threads. Just looped scheduler based on `daemon_controller` and `looper`.
4
- We call it 'Dancer'.
3
+ No forks. No threads. Just looped pseudo-scheduler based on `daemon_controller` and `looper`.
4
+
5
+ One dancer is one daemon.
5
6
 
6
7
  == Easy to install
7
8
 
@@ -29,7 +30,7 @@ LoopDance automatically starts at the rails 3 server startup.
29
30
 
30
31
  From the rails application:
31
32
 
32
- Dancer1.controller.start unless Dancer1.controller.running?
33
+ Dancer1.start unless Dancer1.running?
33
34
 
34
35
  By the rake tasks (TODO):
35
36
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -4,16 +4,13 @@ module LoopDance
4
4
 
5
5
  attr_accessor :tasks, :timeout, :maximal_timeout, :muted_log, :autostart
6
6
 
7
- @autostart = true
8
-
9
- def mute_log
10
- @muted_log = true
11
- end
12
-
13
7
  def disable_autostart
14
8
  @autostart = false
15
9
  end
16
10
 
11
+ def mute_log
12
+ @muted_log = true
13
+ end
17
14
 
18
15
  def every( interval, &block )
19
16
  @tasks = [] unless @tasks
@@ -46,6 +46,21 @@ module LoopDance
46
46
  log_exception exception
47
47
  end
48
48
 
49
+ def safely_restart
50
+ dancer.log "Retarting.. (#{@start_command})"
51
+ if running?
52
+ dancer.log "Dancer is already running, stop"
53
+ stop
54
+ dancer.log "Start"
55
+ start
56
+ else
57
+ start
58
+ dancer.log "Started"
59
+ end
60
+ rescue => exception # DaemonController::StartTimeout
61
+ log_exception exception
62
+ end
63
+
49
64
  def safely_stop
50
65
  dancer.log "Stopping.."
51
66
  stop if running?
@@ -8,15 +8,29 @@ module LoopDance
8
8
  class Dancer
9
9
 
10
10
  extend LoopDance::Commands
11
-
11
+
12
12
  class << self
13
-
14
- # Can start daemon automatically at rails server startup? true by default
13
+
14
+ def inherited(subclass)
15
+ subclass.autostart = true
16
+ end
15
17
 
16
18
  def controller
17
19
  @controller ||= LoopDance::Controller.new self
18
20
  end
19
21
 
22
+ def stop
23
+ controller.stop
24
+ end
25
+
26
+ def start
27
+ controller.start
28
+ end
29
+
30
+ def running?
31
+ controller.running?
32
+ end
33
+
20
34
  end
21
35
 
22
36
  end
@@ -12,7 +12,7 @@ module LoopDance
12
12
  initializer 'loop_dance.initialize' do
13
13
  self.class.load_dancers
14
14
  # Do not start dancers if rake or other tasks
15
- LoopDance.start_all if server_startup?
15
+ LoopDance.restart_all if server_startup?
16
16
  end
17
17
 
18
18
 
data/lib/loop_dance.rb CHANGED
@@ -12,6 +12,13 @@ module LoopDance
12
12
  end
13
13
  end
14
14
 
15
+ def restart_all( force=false )
16
+ return puts "LoopDance: No dancers defined" if LoopDance::Dancer.subclasses.empty?
17
+ LoopDance::Dancer.subclasses.each do |dancer|
18
+ dancer.controller.safely_restart if force || dancer.autostart
19
+ end
20
+ end
21
+
15
22
  def stop_all
16
23
  return puts "LoopDance: No dancers defined" if LoopDance::Dancer.subclasses.empty?
17
24
  LoopDance::Dancer.subclasses.each do |dancer|
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.3.1"
8
+ s.version = "0.4.0"
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-01-02}
12
+ s.date = %q{2011-01-21}
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 = [
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
  "rails_example/config/initializers/session_store.rb",
52
52
  "rails_example/config/locales/en.yml",
53
53
  "rails_example/config/routes.rb",
54
+ "rails_example/db/schema.rb",
54
55
  "rails_example/db/seeds.rb",
55
56
  "rails_example/lib/dancers.rb",
56
57
  "rails_example/lib/tasks/.gitkeep",
@@ -77,7 +78,7 @@ Gem::Specification.new do |s|
77
78
  s.homepage = %q{http://github.com/dapi/loop_dance}
78
79
  s.licenses = ["MIT"]
79
80
  s.require_paths = ["lib"]
80
- s.rubygems_version = %q{1.3.7}
81
+ s.rubygems_version = %q{1.4.2}
81
82
  s.summary = %q{Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup}
82
83
  s.test_files = [
83
84
  "spec/dancer_spec.rb",
@@ -86,7 +87,6 @@ Gem::Specification.new do |s|
86
87
  ]
87
88
 
88
89
  if s.respond_to? :specification_version then
89
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
90
90
  s.specification_version = 3
91
91
 
92
92
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -7,7 +7,7 @@ gem 'rails', '3.0.3'
7
7
 
8
8
  gem "loop_dance", :path => '../'
9
9
 
10
- #gem 'sqlite3-ruby', :require => 'sqlite3'
10
+ gem 'sqlite3-ruby', :require => 'sqlite3'
11
11
 
12
12
  # Use unicorn as the web server
13
13
  # gem 'unicorn'
@@ -0,0 +1,15 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 0) do
14
+
15
+ end
data/spec/dancer_spec.rb CHANGED
@@ -2,13 +2,10 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe LoopDance do
4
4
 
5
- describe "setup" do
6
- end
7
-
8
- describe "finds minimal interval"
9
-
5
+ # describe "finds minimal interval"
6
+
10
7
  describe "examples" do
11
-
8
+
12
9
  before(:all) do
13
10
  class Dancer1 < LoopDance::Dancer
14
11
  every 2.seconds do
@@ -25,8 +22,10 @@ describe LoopDance do
25
22
 
26
23
  it { Dancer1.tasks.count.should == 4 }
27
24
  it { Dancer1.timeout.should == 2 }
28
- it { LoopDance::Dancer.tasks.should be_blank }
29
25
  it { Dancer1.maximal_timeout.should == 10 }
26
+ it { Dancer1.autostart.should be_true }
27
+
28
+ it { LoopDance::Dancer.tasks.should be_blank }
30
29
 
31
30
 
32
31
  describe "another dancer not change first dancer's tasks" do
@@ -44,7 +43,7 @@ describe LoopDance do
44
43
  it { Dancer2.timeout.should == 1 }
45
44
  it { Dancer2.maximal_timeout.should == 11 }
46
45
  it { Dancer2.muted_log.should be_nil }
47
- it { Dancer1.autostart.should be_true }
46
+ it { Dancer2.autostart.should be_true }
48
47
 
49
48
  end
50
49
 
@@ -57,6 +56,7 @@ describe LoopDance do
57
56
  end
58
57
  it { Dancer1.muted_log.should be_true }
59
58
  it { Dancer1.autostart.should be_false }
59
+ it { Dancer1.autostart.should_not be_nil }
60
60
  end
61
61
 
62
62
  describe "find right minimal timeout" do
@@ -12,6 +12,11 @@ namespace :loop_dance do
12
12
  LoopDance.start_all
13
13
  end
14
14
 
15
+ desc "Start restart all dancers"
16
+ task :restart_all => :loop_dance do
17
+ LoopDance.restart_all
18
+ end
19
+
15
20
  desc "Stop all dancers"
16
21
  task :stop_all => :loop_dance do
17
22
  LoopDance.stop_all
@@ -34,6 +39,10 @@ namespace :loop_dance do
34
39
  dancer.controller.safely_start
35
40
  end
36
41
 
42
+ task :restart => :loop_dance do
43
+ dancer.controller.safely_restart
44
+ end
45
+
37
46
  desc "Stop #{dancer}"
38
47
  task :stop => :loop_dance do
39
48
  dancer.controller.safely_stop
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: 17
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Danil Pismenny
@@ -15,12 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-02 00:00:00 +03:00
18
+ date: 2011-01-21 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- name: activesupport
22
+ type: :runtime
24
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
@@ -32,10 +31,10 @@ dependencies:
32
31
  - 0
33
32
  version: "3.0"
34
33
  requirement: *id001
35
- type: :runtime
36
- - !ruby/object:Gem::Dependency
37
34
  prerelease: false
38
- name: i18n
35
+ name: activesupport
36
+ - !ruby/object:Gem::Dependency
37
+ type: :runtime
39
38
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
@@ -46,10 +45,10 @@ dependencies:
46
45
  - 0
47
46
  version: "0"
48
47
  requirement: *id002
49
- type: :runtime
50
- - !ruby/object:Gem::Dependency
51
48
  prerelease: false
52
- name: daemon_controller
49
+ name: i18n
50
+ - !ruby/object:Gem::Dependency
51
+ type: :runtime
53
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
@@ -62,10 +61,10 @@ dependencies:
62
61
  - 5
63
62
  version: 0.2.5
64
63
  requirement: *id003
65
- type: :runtime
66
- - !ruby/object:Gem::Dependency
67
64
  prerelease: false
68
- name: bundler
65
+ name: daemon_controller
66
+ - !ruby/object:Gem::Dependency
67
+ type: :development
69
68
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
@@ -78,10 +77,10 @@ dependencies:
78
77
  - 0
79
78
  version: 1.0.0
80
79
  requirement: *id004
81
- type: :development
82
- - !ruby/object:Gem::Dependency
83
80
  prerelease: false
84
- name: jeweler
81
+ name: bundler
82
+ - !ruby/object:Gem::Dependency
83
+ type: :development
85
84
  version_requirements: &id005 !ruby/object:Gem::Requirement
86
85
  none: false
87
86
  requirements:
@@ -94,10 +93,10 @@ dependencies:
94
93
  - 2
95
94
  version: 1.5.2
96
95
  requirement: *id005
97
- type: :development
98
- - !ruby/object:Gem::Dependency
99
96
  prerelease: false
100
- name: rcov
97
+ name: jeweler
98
+ - !ruby/object:Gem::Dependency
99
+ type: :development
101
100
  version_requirements: &id006 !ruby/object:Gem::Requirement
102
101
  none: false
103
102
  requirements:
@@ -108,10 +107,10 @@ dependencies:
108
107
  - 0
109
108
  version: "0"
110
109
  requirement: *id006
111
- type: :development
112
- - !ruby/object:Gem::Dependency
113
110
  prerelease: false
114
- name: ruby-debug
111
+ name: rcov
112
+ - !ruby/object:Gem::Dependency
113
+ type: :development
115
114
  version_requirements: &id007 !ruby/object:Gem::Requirement
116
115
  none: false
117
116
  requirements:
@@ -122,10 +121,10 @@ dependencies:
122
121
  - 0
123
122
  version: "0"
124
123
  requirement: *id007
125
- type: :development
126
- - !ruby/object:Gem::Dependency
127
124
  prerelease: false
128
- name: rspec
125
+ name: ruby-debug
126
+ - !ruby/object:Gem::Dependency
127
+ type: :development
129
128
  version_requirements: &id008 !ruby/object:Gem::Requirement
130
129
  none: false
131
130
  requirements:
@@ -136,10 +135,10 @@ dependencies:
136
135
  - 0
137
136
  version: "0"
138
137
  requirement: *id008
139
- type: :development
140
- - !ruby/object:Gem::Dependency
141
138
  prerelease: false
142
- name: shoulda
139
+ name: rspec
140
+ - !ruby/object:Gem::Dependency
141
+ type: :development
143
142
  version_requirements: &id009 !ruby/object:Gem::Requirement
144
143
  none: false
145
144
  requirements:
@@ -150,7 +149,8 @@ dependencies:
150
149
  - 0
151
150
  version: "0"
152
151
  requirement: *id009
153
- type: :development
152
+ prerelease: false
153
+ name: shoulda
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: []
@@ -195,6 +195,7 @@ files:
195
195
  - rails_example/config/initializers/session_store.rb
196
196
  - rails_example/config/locales/en.yml
197
197
  - rails_example/config/routes.rb
198
+ - rails_example/db/schema.rb
198
199
  - rails_example/db/seeds.rb
199
200
  - rails_example/lib/dancers.rb
200
201
  - rails_example/lib/tasks/.gitkeep
@@ -247,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
248
  requirements: []
248
249
 
249
250
  rubyforge_project:
250
- rubygems_version: 1.3.7
251
+ rubygems_version: 1.4.2
251
252
  signing_key:
252
253
  specification_version: 3
253
254
  summary: Daemon builder and controller. Easy setup and managed from the rails application or rake tasks. Autostart at rails server startup