Skip to content

Commit

Permalink
Create worker for refreshing tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed Nov 1, 2012
1 parent b940a91 commit 33a0218
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: bundle exec rails server thin -p $PORT
web: bundle exec rails server thin -p $PORT
worker: bundle exec rake refresh_tweets_worker
3 changes: 2 additions & 1 deletion app/models/hug_app_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def update_tweets
Twitter.search(term, include_entities: true, rpp: 50, result_type: "recent").each do |tweet|
Tweet.create_or_skip(tweet)
end
sleep(5)
end

puts "Success!"
Expand Down Expand Up @@ -92,6 +91,8 @@ def self.create_or_skip(tweet, skip_tweet_validation = false)
# it and resave it
new_tweet.remote_image_url = @media_url
new_tweet.save!

puts "Created tweet @#{new_tweet.username}: #{new_tweet.tweet_text}"
end

end
Expand Down
11 changes: 10 additions & 1 deletion lib/tasks/refresh_tweets.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
desc "Refresh the app with friends from twitter"
task :refresh_tweets => :environment do
RUBYFRIENDS_APP.refresh_tweets
end
end

desc "Refresh tweets every minute"
task :refresh_tweets_worker => :environment do
loop do
RUBYFRIENDS_APP.refresh_tweets
puts "Sleeping for 60 seconds..."
sleep 60
end
end

0 comments on commit 33a0218

Please sign in to comment.