loops 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -154,6 +154,24 @@ the loop class to execute:
154
154
  Now two independent sets of loops are using the same class <tt>SomeModule::MyWorkerLoop</tt>
155
155
  customized by the language parameter.
156
156
 
157
+ == How to initialize the loop before workers run?
158
+
159
+ You can run initialization code before starting loop workers by implementing the initialize_loop class method. If
160
+ initialize_loop raises an error, then the loop is not started and the error is logged.
161
+
162
+ class HelloWorldLoop < Loops::Base
163
+ def self.initialize_loop(config)
164
+ raise "Missing required dependency" unless File.exist?(config['my_dependency'])
165
+ end
166
+
167
+ def run
168
+ with_period_of(1) do # period is in seconds
169
+ debug("Hello, debug log!")
170
+ sleep(config['sleep_period']) # Do something "useful" and make it configurable
171
+ debug("Hello, debug log (yes, once again)!")
172
+ end
173
+ end
174
+ end
157
175
 
158
176
  == I want to keep my loop running on machine reboots. How to do it?
159
177
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 3
4
- :major: 2
5
3
  :build:
4
+ :patch: 4
5
+ :major: 2
@@ -120,6 +120,17 @@ class Loops::Engine
120
120
  info "Starting loop: #{name}"
121
121
  info " - config: #{config.inspect}"
122
122
 
123
+ begin
124
+ if klass.respond_to?(:initialize_loop)
125
+ debug "Initializing loop"
126
+ klass.initialize_loop(config)
127
+ debug "Initialization successful"
128
+ end
129
+ rescue Exception => e
130
+ error("Initialization failed: #{e.message}\n " + e.backtrace.join("\n "))
131
+ return
132
+ end
133
+
123
134
  loop_proc = Proc.new do
124
135
  the_logger = begin
125
136
  if Loops.logger.is_a?(Loops::Logger) && @global_config['workers_engine'] == 'fork'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{loops}
8
- s.version = "2.0.3"
8
+ s.version = "2.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexey Kovyrin", "Dmytro Shteflyuk"]
12
- s.date = %q{2010-04-01}
12
+ s.date = %q{2010-07-30}
13
13
  s.description = %q{Loops is a small and lightweight framework for Ruby on Rails, Merb and other ruby frameworks created to support simple background loops in your application which are usually used to do some background data processing on your servers (queue workers, batch tasks processors, etc).}
14
14
  s.email = %q{alexey@kovyrin.net}
15
15
  s.executables = ["loops", "loops-memory-stats"]
@@ -70,7 +70,7 @@ Gem::Specification.new do |s|
70
70
  s.homepage = %q{http://github.com/kovyrin/loops}
71
71
  s.rdoc_options = ["--charset=UTF-8"]
72
72
  s.require_paths = ["lib"]
73
- s.rubygems_version = %q{1.3.6}
73
+ s.rubygems_version = %q{1.3.7}
74
74
  s.summary = %q{Simple background loops framework for ruby}
75
75
  s.test_files = [
76
76
  "spec/loop_lock_spec.rb",
@@ -89,7 +89,7 @@ Gem::Specification.new do |s|
89
89
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
90
90
  s.specification_version = 3
91
91
 
92
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
92
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
93
93
  else
94
94
  end
95
95
  else
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loops
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
- - 3
9
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Alexey Kovyrin
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-04-01 00:00:00 -04:00
19
+ date: 2010-07-30 00:00:00 -04:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
@@ -88,23 +89,27 @@ rdoc_options:
88
89
  require_paths:
89
90
  - lib
90
91
  required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
91
93
  requirements:
92
94
  - - ">="
93
95
  - !ruby/object:Gem::Version
96
+ hash: 3
94
97
  segments:
95
98
  - 0
96
99
  version: "0"
97
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
98
102
  requirements:
99
103
  - - ">="
100
104
  - !ruby/object:Gem::Version
105
+ hash: 3
101
106
  segments:
102
107
  - 0
103
108
  version: "0"
104
109
  requirements: []
105
110
 
106
111
  rubyforge_project:
107
- rubygems_version: 1.3.6
112
+ rubygems_version: 1.3.7
108
113
  signing_key:
109
114
  specification_version: 3
110
115
  summary: Simple background loops framework for ruby