1

I have a little script streaming data from Twitter and feeding it to another application. I am using for that the official twitter gem in its 5.0.0.rc.1 release with the streaming feature being flagged as experimental, which is fine with me. It's not a critical application anyway.

In order to have it withstand unforeseen crashes and other networking problems and so, I have this script monitored by god (0.13.3) and it works indeed most of the time. For some reason though it appears that occasionally the script will completely hang and sit idly while tweets should be received every odd second (debug setup is using widely used terms).

ps lists it as Ss, consuming 0% CPU and a mere 25MB of RAM.

I believe there might be some gotchas in the twitter gem (or a dependency) and I do not have the leisure to dive into the code now and try to fix it.

God.watch do |w|
  w.name = 'twitter-streamer'
  w.env = {
    'TWITTER_CONSUMER_KEY' => 'key',
    'TWITTER_CONSUMER_SECRET' => 'secret',
    'TWITTER_ACCESS_TOKEN' => 'token',
    'TWITTER_ACCESS_TOKEN_SECRET' => 'very_secret'
  }
  w.start = "twitter_streamer --hashtags cheese"
  w.keepalive
  w.log = File.join APP_HOME, 'log', 'twitter-streamer.log'
end

This is the definition of my watch. As you can see, it's pretty much by the book. What I would like, is a condition that would allow me to forcefully restart the process every so often. That would is an acceptable workaround for my needs.

Perhaps something like

# lifecycle
w.lifecycle do |on|
  on.condition(:every) do |c|         
    c.within = 15.minute
    c.transition = :restart
  end
end

This is based off the :flapping condition block sample on the project's homepage. Is there a way to achieve this or would I need to implement my own condition?

4

0 回答 0