billymeltdown-looper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +3 -3
- data/lib/looper.rb +2 -2
- data/looper.gemspec +1 -1
- metadata +1 -1
data/README.textile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Looper is a dead simple Ruby module for daemonizing your code, meant for use with Rails' script/runner. No forking involved, no detaching, simply running a nice healthy loop, but allowing your code to bail out of it, and making it responsive to signals.
|
2
2
|
|
3
|
-
You implement a class like "DoSomething" that checks for new message objects and then does something to them. This class will include Looper in order to easily loop, respond to shutdown signals, and it can then be run via script/runner as a daemon.
|
3
|
+
You implement a class like "DoSomething" that checks for new message objects and then does something to them. This class will include @Looper@ in order to easily loop, respond to shutdown signals, and it can then be run via script/runner as a daemon.
|
4
4
|
|
5
|
-
The loop handles sleeping between runs, and will catch any unhandled exceptions that bubble up and keep on truckin'. Thus, if you want to exit on a particular exception, you've got to rescue it in your code and set
|
5
|
+
The loop handles sleeping between runs, and will catch any unhandled exceptions that bubble up and keep on truckin'. Thus, if you want to exit on a particular exception, you've got to rescue it in your code and set @@run@ to @false@.
|
6
6
|
|
7
7
|
Here's an example usage:
|
8
8
|
|
@@ -41,6 +41,6 @@ DoSomething.new( { :sleep => 10 } ).run
|
|
41
41
|
|
42
42
|
Now we can just kick that off any way we like and background the process, but we tend to use it with script/runner in our Rails environments to have access to our models and such. It boils down to:
|
43
43
|
|
44
|
-
|
44
|
+
@$ nohup script/runner -e RAILS_ENV /path/to/DoSomething.rb@
|
45
45
|
|
46
46
|
And then looking up the PID by matching on /path/to/DoSomething.rb via grep and use kill to send the term signal.
|
data/lib/looper.rb
CHANGED
@@ -43,10 +43,10 @@ module Looper
|
|
43
43
|
|
44
44
|
puts "#{Time.now} process started with #{run_every} loop. kill #{Process.pid} to stop"
|
45
45
|
|
46
|
-
last_run = Time.now - run_every
|
46
|
+
last_run = Time.now - run_every - 1
|
47
47
|
while (@run) do
|
48
48
|
now = Time.now
|
49
|
-
if last_run + run_every
|
49
|
+
if last_run + run_every < now
|
50
50
|
begin
|
51
51
|
yield
|
52
52
|
rescue Exception => e
|
data/looper.gemspec
CHANGED