loops 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -19
- data/lib/loops/engine.rb +5 -2
- data/lib/loops/process_manager.rb +8 -2
- data/lib/loops/version.rb +1 -1
- metadata +6 -8
data/README.rdoc
CHANGED
@@ -35,26 +35,18 @@ you're going to like it.
|
|
35
35
|
|
36
36
|
== How to install?
|
37
37
|
|
38
|
-
|
38
|
+
Add the loops gem to your +Gemfile+:
|
39
39
|
|
40
|
-
|
41
|
-
* install as a Rails plugin
|
40
|
+
gem 'loops'
|
42
41
|
|
43
|
-
|
42
|
+
And then run +bundle+ command.
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
And then run the command:
|
48
|
-
|
49
|
-
sudo rake gems:install
|
50
|
-
|
51
|
-
To install loops as a Rails plugin you need to do rhw following:
|
44
|
+
To install loops as a Rails plugin you need to do the following:
|
52
45
|
|
53
46
|
./script/plugin install git://github.com/kovyrin/loops.git
|
54
47
|
|
55
|
-
This will install the whole package in your vendor/plugins directory.
|
56
|
-
For merb applications, just check out the code and place it to the vendor/plugins directory.
|
57
|
-
|
48
|
+
This will install the whole package in your +vendor/plugins+ directory.
|
49
|
+
For merb applications, just check out the code and place it to the +vendor/plugins+ directory.
|
58
50
|
|
59
51
|
After you are done with the installation, you need to generate binary and configuration
|
60
52
|
files by running:
|
@@ -62,10 +54,10 @@ files by running:
|
|
62
54
|
./script/generate loops
|
63
55
|
|
64
56
|
This will create the following list of files:
|
65
|
-
* <tt>./script/loops</tt>
|
66
|
-
* <tt>./config/loops.yml</tt>
|
67
|
-
* <tt>./app/loops/simple.rb</tt>
|
68
|
-
* <tt>./app/loops/queue_loop.rb</tt>
|
57
|
+
* <tt>./script/loops</tt> -- binary file that will be used to manage your loops
|
58
|
+
* <tt>./config/loops.yml</tt> -- example configuration file
|
59
|
+
* <tt>./app/loops/simple.rb</tt> -- REALLY simple loop example
|
60
|
+
* <tt>./app/loops/queue_loop.rb</tt> -- simple ActiveMQ queue worker
|
69
61
|
|
70
62
|
|
71
63
|
== How to use?
|
@@ -177,12 +169,18 @@ initialize_loop raises an error, then the loop is not started and the error is l
|
|
177
169
|
|
178
170
|
We use monit to keep loop monitors runnings. You could use something like this in your configs:
|
179
171
|
|
172
|
+
check process loop-slow_logs with pidfile /your/project/current/tmp/pids/loop-slow_logs.pid
|
173
|
+
group loops
|
174
|
+
start program "/bin/bash -c 'cd /your/project/current && /usr/bin/bundle exec loops start slow_logs -p /your/project/shared/pids/loop-slow_logs.pid -e loops -d'"
|
175
|
+
stop program "/bin/bash -c 'cd /your/project/current && /usr/bin/bundle exec loops stop -p /your/project/shared/pids/loop-slow_logs.pid'"
|
176
|
+
|
177
|
+
If you do not use bundler, you can do:
|
178
|
+
|
180
179
|
check process loop-slow_logs with pidfile /your/project/current/tmp/pids/loop-slow_logs.pid
|
181
180
|
group loops
|
182
181
|
start program "/your/project/current/script/loops start slow_logs -e loops -p tmp/pids/loop-slow_logs.pid -d"
|
183
182
|
stop program "/your/project/current/script/loops stop slow_logs -e loops -p tmp/pids/loop-slow_logs.pid"
|
184
183
|
|
185
|
-
|
186
184
|
== ActiveMQ-based workers? What's that?
|
187
185
|
|
188
186
|
In some of our worker loops we poll ActiveMQ queue and process its items to perform some
|
data/lib/loops/engine.rb
CHANGED
@@ -172,6 +172,9 @@ class Loops::Engine
|
|
172
172
|
if config['debug_loop']
|
173
173
|
loop_proc.call
|
174
174
|
else
|
175
|
+
# If wait_period is specified for the loop, update ProcessManager's
|
176
|
+
# setting.
|
177
|
+
@pm.update_wait_period(config['wait_period']) if config['wait_period']
|
175
178
|
@pm.start_workers(name, config['workers_number'] || 1) { loop_proc.call }
|
176
179
|
end
|
177
180
|
end
|
@@ -205,9 +208,9 @@ class Loops::Engine
|
|
205
208
|
|
206
209
|
def fix_ar_after_fork
|
207
210
|
if Object.const_defined?('ActiveRecord')
|
208
|
-
if
|
211
|
+
if ActiveRecord::VERSION::MAJOR < 3
|
209
212
|
ActiveRecord::Base.allow_concurrency = true
|
210
|
-
|
213
|
+
elsif Object.const_defined?('Rails')
|
211
214
|
Rails.application.config.allow_concurrency = true
|
212
215
|
end
|
213
216
|
ActiveRecord::Base.clear_active_connections!
|
@@ -5,7 +5,8 @@ module Loops
|
|
5
5
|
def initialize(config, logger)
|
6
6
|
@config = {
|
7
7
|
'poll_period' => 1,
|
8
|
-
'
|
8
|
+
'wait_period' => 10,
|
9
|
+
'workers_engine' => 'fork',
|
9
10
|
}.merge(config)
|
10
11
|
|
11
12
|
@logger = logger
|
@@ -13,6 +14,11 @@ module Loops
|
|
13
14
|
@shutdown = false
|
14
15
|
end
|
15
16
|
|
17
|
+
def update_wait_period(period)
|
18
|
+
return unless period
|
19
|
+
@config['wait_period'] = [@config['wait_period'], period].max
|
20
|
+
end
|
21
|
+
|
16
22
|
def start_workers(name, number, &blk)
|
17
23
|
raise ArgumentError, "Need a worker block!" unless block_given?
|
18
24
|
|
@@ -42,7 +48,7 @@ module Loops
|
|
42
48
|
stop_workers(false)
|
43
49
|
|
44
50
|
# Wait for all the workers to die
|
45
|
-
unless wait_for_workers(
|
51
|
+
unless wait_for_workers(@config['wait_period'])
|
46
52
|
logger.info("Some workers are still alive after 10 seconds of waiting. Killing them...")
|
47
53
|
stop_workers(true)
|
48
54
|
wait_for_workers(5)
|
data/lib/loops/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 7
|
10
|
+
version: 2.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexey Kovyrin
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-06-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-06-28 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: rspec
|
@@ -108,7 +107,6 @@ files:
|
|
108
107
|
- spec/rails/config/init.rb
|
109
108
|
- spec/rails/config/loops.yml
|
110
109
|
- spec/spec_helper.rb
|
111
|
-
has_rdoc: true
|
112
110
|
homepage: http://github.com/kovyrin/loops
|
113
111
|
licenses: []
|
114
112
|
|
@@ -138,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
136
|
requirements: []
|
139
137
|
|
140
138
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.
|
139
|
+
rubygems_version: 1.8.5
|
142
140
|
signing_key:
|
143
141
|
specification_version: 3
|
144
142
|
summary: Simple background loops framework for ruby
|