loop_dance 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
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.2.5
1
+ 0.3.1
@@ -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, :start_timeout
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
@@ -12,8 +12,6 @@ module LoopDance
12
12
  class << self
13
13
 
14
14
  # Can start daemon automatically at rails server startup? true by default
15
- cattr_accessor :start_automatic
16
- self.start_automatic = true
17
15
 
18
16
  def controller
19
17
  @controller ||= LoopDance::Controller.new self
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.start_automatic
11
+ dancer.controller.safely_start if force || dancer.autostart
12
12
  end
13
13
  end
14
14
 
data/loop_dance.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{loop_dance}
8
- s.version = "0.2.5"
8
+ s.version = "0.3.1"
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"]
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: 29
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 5
10
- version: 0.2.5
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Danil Pismenny