loops 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -149,6 +149,7 @@ the loop class to execute:
149
149
  Now two independent sets of loops are using the same class <tt>SomeModule::MyWorkerLoop</tt>
150
150
  customized by the language parameter.
151
151
 
152
+
152
153
  == How to initialize the loop before workers run?
153
154
 
154
155
  You can run initialization code before starting loop workers by implementing the initialize_loop class method. If
@@ -168,6 +169,17 @@ initialize_loop raises an error, then the loop is not started and the error is l
168
169
  end
169
170
  end
170
171
 
172
+
173
+ == How do I detect if my code is running in a loop?
174
+
175
+ We provide an api call <tt>Loops.running?</tt> that returns <tt>true</tt> if your code is running as a part of a loops process.
176
+ For example, if you want your Rails.logger to write logs into your Loops logger (when you run it in a loop), you could do something
177
+ like the following in your environment files:
178
+
179
+ # Switch logger to loops if we are in a loops process
180
+ config.logger = Loops.logger if Loops.running?
181
+
182
+
171
183
  == I want to keep my loop running on machine reboots. How to do it?
172
184
 
173
185
  We use monit to keep loop monitors runnings. You could use something like this in your configs:
@@ -184,6 +196,7 @@ If you do not use bundler, you can do:
184
196
  start program "/your/project/current/script/loops start slow_logs -e loops -p tmp/pids/loop-slow_logs.pid -d"
185
197
  stop program "/your/project/current/script/loops stop slow_logs -e loops -p tmp/pids/loop-slow_logs.pid"
186
198
 
199
+
187
200
  == ActiveMQ-based workers? What's that?
188
201
 
189
202
  In some of our worker loops we poll ActiveMQ queue and process its items to perform some
@@ -14,14 +14,15 @@ module Loops
14
14
  #
15
15
  # Usually it is initialized with framework's root dir (RAILS_ROOT or MERB_ROOT),
16
16
  # but you can specify another directory using command line arguments.
17
+ # Default: current directory.
17
18
  #
18
19
  # Loops current directory will is set to this value (chdir).
19
20
  #
20
- # @return [Pathname, nil]
21
+ # @return [Pathname]
21
22
  # the loops root directory.
22
23
  #
23
24
  def self.root
24
- @@root
25
+ @@root ||= Pathname.new('').realpath
25
26
  end
26
27
 
27
28
  # Set loops root directory.
@@ -162,6 +163,12 @@ module Loops
162
163
  def self.default_logger=(logger)
163
164
  @@default_logger = logger
164
165
  end
166
+
167
+ # Returns true if current process is started with loops CLI
168
+ #
169
+ def self.running?
170
+ Loops::CLI.running?
171
+ end
165
172
  end
166
173
 
167
174
  require File.join(Loops::LIB_ROOT, 'loops/autoload')
@@ -13,10 +13,22 @@ module Loops
13
13
  end
14
14
 
15
15
  module ClassMethods
16
+ # We set this to true when a command is running
17
+ @@running = false
18
+
19
+ # Returns running status
20
+ #
21
+ def running?
22
+ @@running
23
+ end
24
+
16
25
  # Parse arguments, find and execute command requested.
17
26
  #
18
27
  def execute
28
+ @@running = true
19
29
  parse(ARGV).run!
30
+ ensure
31
+ @@running = false
20
32
  end
21
33
 
22
34
  # Register a Loops command.
@@ -7,7 +7,7 @@ module Loops
7
7
  module Version
8
8
  MAJOR = 2
9
9
  MINOR = 0
10
- PATCH = 8
10
+ PATCH = 9
11
11
  BUILD = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 8
10
- version: 2.0.8
9
+ - 9
10
+ version: 2.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oleksiy Kovyrin