huginn / huginn

Create agents that monitor and act on your behalf. Your agents are standing by!
MIT License
43.12k stars 3.75k forks source link

Twitter streaming agent hangs after few hours #904

Closed msenthilvel closed 9 years ago

msenthilvel commented 9 years ago

Hello, I am trying to deploy huginn as an alternative to yahoo pipes. I was able to deploy successfully after reading through several issues and following a guide posted for manual installation. However, for some strange reason twitter stream agent seems to exit/hang after few hours (2-3 hrs max) in production mode and am not able to get any feeds after that. Have also tried changing the procfile to use the old version instead of threaded version but that didn't solve this problem. Also when I stop the huginn service and then start them through "foreman start" to check for errors I found a weird line "Twitter error: Invalid Status code 420". Is it in anyway connected or am I doing something wrong? any info would be really helpful.

virtadpt commented 9 years ago

How many copies of the TwitterStreamAgent do you have deployed in your instance? Twitter's API service sends back an Error 420 (Enhance Your Calm) when you're being rate limited: https://dev.twitter.com/rest/public/rate-limiting

If you can, fold your TwitterStreamAgent instances into a single instance, feed the event stream into a copy of EventFormattingAgent to build messages of whatever kind you need, and then feed the event stream into one or more instances of TriggerAgent to sort them.

msenthilvel commented 9 years ago

Mmm, that's weird as I was running only one TwitterStreamAgent. Is there anything else that can potentially cause huginn to be rate limited by twitter? Also, I will restart my huginn instance through foreman start again and let you know if I could track the error more precisely, Thanks!

dsander commented 9 years ago

@msenthilvel also make sure you just have one threaded worker running. I am getting 420 errors when I use the same twitter credentials locally in development and in production, the same probably happens if a old instance of the threaded worker did not shut down properly.

msenthilvel commented 9 years ago

Thanks, that solved my problem. Seems like one of the old instance has been running in the background since I probably did not shut down the processes properly while trying to debug them. Thanks again! :)

dsander commented 9 years ago

Glad it works now :smile:

cantino commented 9 years ago

I added a "debugging Twitter" section to https://github.com/cantino/huginn/wiki/Configuring-OAuth-applications#debugging-twitter -- how's it look?

msenthilvel commented 9 years ago

Now that the source of error is known, my twitter stream keeps hanging and on analysis (htop command) I could see more than one twitter_stream.rb process. Is there a way to restrict them from spawning more than once ? I've also confirmed that there is no process open while starting huginn in production, so pretty sure it isn't a old instance. Sorry to post it in an closed issue, thought it would be appropriate to post it in here.

cantino commented 9 years ago

Hey @msenthilvel, how are you starting / running Huginn?

msenthilvel commented 9 years ago

wrote a init script that does the following in the order given: bundle exec unicorn -E production -c config/unicorn.rb bundle exec rails runner bin/schedule.rb bundle exec rails runner bin/twitter_stream.rb bundle exec script/delayed_job run All commands are run as a separate user 'huginn' with disabled login.

cantino commented 9 years ago

Is it possible that one of those processes is getting run more than once?

/cc @dsander

dsander commented 9 years ago

@msenthilvel Maybe your init script does not properly shut down the old processes before restarting the new version?