acts_as_service 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -6,4 +6,6 @@ put things in here that could be worked on
6
6
  * extricate the gem from needing to run within Rails (maybe nothing to do here,
7
7
  maybe just coming up with different pidfile default path if RAILS_ROOT
8
8
  isn't defined. but including class can always just specify explicit path and
9
- should be fine
9
+ should be fine
10
+ * incorporate ability for service to define a logger that will be used by
11
+ the acts as service infrastruture (vs. just logging to stdout)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_service}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Percival"]
12
- s.date = %q{2010-02-18}
12
+ s.date = %q{2010-11-05}
13
13
  s.description = %q{A gem with a mixin to let you turn a class into something that runs like a service,
14
14
  which you can MyService.start, MyService.stop, and MyService.restart. It tracks
15
15
  its own pid. For now, pretty sure it requires that the class is running inside
@@ -30,14 +30,14 @@ probably be changed without too much difficulty.
30
30
  s.homepage = %q{http://github.com/bmpercy/acts_as_service}
31
31
  s.rdoc_options = ["--charset=UTF-8"]
32
32
  s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.5}
33
+ s.rubygems_version = %q{1.3.7}
34
34
  s.summary = %q{Makes it very easy to create a service-like class that's easy to start and stop, taken from work at discovereads.com}
35
35
 
36
36
  if s.respond_to? :specification_version then
37
37
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
38
  s.specification_version = 3
39
39
 
40
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
41
  else
42
42
  end
43
43
  else
@@ -21,6 +21,13 @@
21
21
  # default is #{RAILS_ROOT}/tmp/pids/<underscore version of service name>
22
22
  # - self.sleep_time: seconds to sleep between calls to peform_work_chunk
23
23
  # default: no sleep till brooklyn!
24
+ # - self.sleep_check_timeout: while 'sleeping' between work chunks, how many
25
+ # seconds to sleep between checking if the
26
+ # service has been shut down. default is 2 seconds,
27
+ # but you may want to override to make shorter
28
+ # (will give better resolution on sleep_time, but
29
+ # uses a little more cpu) or longer (if you don't
30
+ # care about how quickly the service shuts down)
24
31
  # - self.after_start: a hook to run a method after the service is started
25
32
  # but before first call to perform_work_chunk
26
33
  # - self.before_stop: a hook to run a method before final shutdown (and
@@ -50,6 +57,13 @@ module ActsAsService
50
57
  ACTS_AS_SERVICE_SHUTTING_DOWN = 'shutting down'
51
58
  ACTS_AS_SERVICE_PID_NO_PROCESS = 'pid no process'
52
59
 
60
+ # how long to sleep before checking to see if sleep time has elapsed...allows
61
+ # for sleeping for a long time between work chunks, but quicker response to
62
+ # shutdowns. this is measured in seconds
63
+ # this is the DEFAULT value if the service doesn't define the
64
+ # +sleep_check_timeout+ method itself
65
+ SLEEP_CHECK_TIMEOUT = 2
66
+
53
67
  def self.included(base)
54
68
  base.extend ClassMethods
55
69
  end
@@ -75,12 +89,25 @@ module ActsAsService
75
89
  if self.respond_to?(:after_start)
76
90
  after_start
77
91
  end
92
+ _sleep_till = Time.now - 1
78
93
  while (_status == ACTS_AS_SERVICE_RUNNING)
79
- # only sleep if asked to
80
- if self.respond_to?(:sleep_time)
81
- sleep sleep_time
94
+ if Time.now >= _sleep_till
95
+ perform_work_chunk
96
+
97
+ # only reset sleep till if asked to; otherwise, just perform next
98
+ # work chunk right away (never change _sleep_till)
99
+ if self.respond_to?(:sleep_time)
100
+ _sleep_till = Time.now + self.sleep_time
101
+ end
102
+ else
103
+ _check_time_interval = if self.respond_to? :sleep_check_timeout
104
+ self.sleep_check_timeout
105
+ else
106
+ SLEEP_CHECK_TIMEOUT
107
+ end
108
+
109
+ sleep [_check_time_interval, _sleep_till - Time.now].min
82
110
  end
83
- perform_work_chunk
84
111
  end
85
112
  puts "Shutting down #{_display_name} (#{_pid})"
86
113
  File.delete(_pid_filename)
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Brian Percival
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-18 00:00:00 -08:00
18
+ date: 2010-11-05 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -45,21 +51,27 @@ rdoc_options:
45
51
  require_paths:
46
52
  - lib
47
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
48
55
  requirements:
49
56
  - - ">="
50
57
  - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
51
61
  version: "0"
52
- version:
53
62
  required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
54
64
  requirements:
55
65
  - - ">="
56
66
  - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
57
70
  version: "0"
58
- version:
59
71
  requirements: []
60
72
 
61
73
  rubyforge_project:
62
- rubygems_version: 1.3.5
74
+ rubygems_version: 1.3.7
63
75
  signing_key:
64
76
  specification_version: 3
65
77
  summary: Makes it very easy to create a service-like class that's easy to start and stop, taken from work at discovereads.com