Tweetstream foreman not working until killed

126 views Asked by At

I'm using the TweetStream gem for rails 3.2 with ruby 1.9.3 as a background process to run code as tweets are pulled in. I've got it working using rails runner, but now I want to move it to heroku, so I've set it up as a rake task. The process appears to start correctly, but when it receives a tweet, nothing happens until I ctrl-c kill foreman, afterwhich I immediately see a backlog of the tweets that should've been registered at the time of. Any idea why this would occur? What is holding them up from being processed during normal operation?

require 'tweetstream'

namespace :jobs do
desc "Workers"
  task :tweetstream => :environment do  

    TweetStream.configure do |config|
        config.consumer_key = ENV["TWITTER_CONSUMER_KEY"]
        config.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
        config.oauth_token = ENV["TWITTER_OAUTH_TOKEN"]
        config.oauth_token_secret = ENV["TWITTER_OAUTH_TOKEN_SECRET"]
        config.auth_method = :oauth
    end     
    TweetStream::Client.new().userstream do |status|
        puts "Received tweet: #{status[:text]}"
        #exec('ruby ./script/tweetstream.rb') (what this would normally be)
    end

end end

Procfile

web: bundle exec rails server -p $PORT
tweetstream: bundle exec rake jobs:tweetstream

Output:

 $ foreman start
 01:58:14 web.1         | started with pid 36088
 01:58:14 tweetstream.1 | started with pid 36089
 01:58:24 web.1         | [2013-12-22 01:58:24] INFO  WEBrick 1.3.1
 01:58:24 web.1         | [2013-12-22 01:58:24] INFO  ruby 1.9.3 (2013-06-27) [x86_64-    darwin12.3.0]
 01:58:24 web.1         | [2013-12-22 01:58:24] INFO  WEBrick::HTTPServer#start: pid=36088 port=5000
 ^CSIGINT received
 01:59:17 system        | sending SIGTERM to all processes
 SIGTERM received
 01:59:17 web.1         | [2013-12-22 01:59:17] INFO  going to shutdown ...
 01:59:17 tweetstream.1 | rake aborted!
 01:59:17 web.1         | [2013-12-22 01:59:17] INFO  WEBrick::HTTPServer#start done.
 01:59:17 tweetstream.1 | /Users/patrickmarx/.rvm/gems/ruby-1.9.3-p448/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine'
 01:59:17 tweetstream.1 | /Users/patrickmarx/.rvm/gems/ruby-1.9.3-p448/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
 01:59:17 tweetstream.1 | /Users/patrickmarx/.rvm/gems/ruby-1.9.3-p448/gems/tweetstream-2.5.0/lib/tweetstream/client.rb:388:in `start'
 01:59:17 tweetstream.1 | /Users/patrickmarx/.rvm/gems/ruby-1.9.3-p448/gems/tweetstream-2.5.0/lib/tweetstream/client.rb:138:in `userstream'
 01:59:17 tweetstream.1 | /Users/patrickmarx/bridgeproject/src/website/bridgeproject_website/lib/tasks/tweetstream.rake:14:in `block (2 levels) in <top (required)>'
 01:59:17 tweetstream.1 | Tasks: TOP => jobs:tweetstream
 01:59:17 tweetstream.1 | (See full trace by running task with --trace)
 01:59:17 web.1         | => Booting WEBrick
 01:59:17 web.1         | => Rails 3.2.14 application starting in development on http://0.0.0.0:5000
 01:59:17 web.1         | => Call with -d to detach
 01:59:17 web.1         | => Ctrl-C to shutdown server
 01:59:17 web.1         | Exiting
 01:59:17 tweetstream.1 | Received tweet: deeeeeeez
 01:59:17 tweetstream.1 | Received tweet: nutz
 01:59:17 tweetstream.1 | Received tweet: are
 01:59:17 tweetstream.1 | exited with code 1
 01:59:17 web.1         | exited with code 0
0

There are 0 answers