我正在使用带有ruby 1.9.3的rails 3.2的TweetStream gem作为后台进程来运行代码,因为推文已被拉入。我已经使用rails runner工作了,但现在我想把它移到heroku所以我把它设置为rake任务。这个过程似乎开始正确,但是当它收到一条推文时,没有任何事情发生,直到我ctrl-c杀死领班,之后我立即看到应该在当时注册的推文的积压。知道为什么会这样吗?是什么阻碍了他们在正常操作中被处理?
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
端 端
Procfile
web: bundle exec rails server -p $PORT
tweetstream: bundle exec rake jobs:tweetstream
输出:
$ 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