GitXplorerGitXplorer
b

looper

public
26 stars
3 forks
0 issues

Commits

List of commits on branch master.
Unverified
d95ec29066a336b4c5cdf6ba0cd4dd36c0dfab02

Merge pull request #1 from diedthreetimes/master

bbillymeltdown committed 13 years ago
Unverified
8bb0e0fd855b9f2d0088e4887f7d4b7cebfaa9d4

Match a regex not string

ddiedthreetimes committed 13 years ago
Unverified
8dd5af4549404c77bcf99095d0e20c2cd9b3d46b

Allow win64 to also work correctly.

ddiedthreetimes committed 13 years ago
Unverified
a954908bf0164afbeb2d1dec9ef026d271738c01

Correctly identify windows

ddiedthreetimes committed 13 years ago
Unverified
a8d41509ffc92c56da3bcf0f836a9d067ca546c7

Add support for windows

ddiedthreetimes committed 13 years ago
Unverified
d1aed9f962583d5c46ad3b01f8e3608bb900534c

Trying to get the gem working properly...

bbillymeltdown committed 16 years ago

README

The README file for this repository.

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.

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.

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@.

Here's an example usage:

require 'looper'

class DoSomething
  include Looper
  
  attr_accessor :run
  
  def initialize(config)
    @run = true
    # do config stuff, etc...
    @sleep = config[:sleep].nil? ? 60 : config[:sleep]
  end # initialize
  
  def run
    loopme(@sleep) do
      begin
        # this is where the meat of your code goes...
        messages = twitter.direct_messages({:since => since.strftime("%a, %d %b %Y %H:%M:%S %Z")})
      rescue Twitter::EpicFailure => e
        puts "bailing out, dude!"
        # set run to false to put the kabosh on the next run
        @run = false
      end
    end
  end
end

# and here's how we kick it off:
DoSomething.new( { :sleep => 10 } ).run

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:

@$ nohup script/runner -e RAILS_ENV /path/to/DoSomething.rb@

And then looking up the PID by matching on /path/to/DoSomething.rb via grep and use kill to send the term signal.