From 53629edde5bbe0d40f244171c5a3a0bae89c9fe4 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 26 Apr 2010 17:44:18 +0300 Subject: [PATCH] Making timeout for FB requests --- online/app/controllers/user_controller.rb | 47 +++++++++++++++++++++++-------- online/app/views/user/facebook_error.erb | 2 +- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/online/app/controllers/user_controller.rb b/online/app/controllers/user_controller.rb index 199f554..f2122b0 100644 --- a/online/app/controllers/user_controller.rb +++ b/online/app/controllers/user_controller.rb @@ -1,3 +1,5 @@ +require 'timeout' + class UserController < ApplicationController before_filter :source_statistic @@ -176,11 +178,21 @@ class UserController < ApplicationController if user_has_published_once == true - session_new.batch do - users_array.each do |player| - player.first_name - end - end + begin + timeout 7 do + session_new.batch do + users_array.each do |player| + player.first_name + end + end + end + rescue TimeoutError + Rails.logger.warn " >" * 15 + Rails.logger.warn " TIMEOUT FOR GETTING NAMES " + Rails.logger.warn " >" * 15 + render :action => :facebook_error + + end time_counter ("Batching first names") @@ -263,14 +275,25 @@ class UserController < ApplicationController feeds_to_publish.push new_params threads = [] threads << Thread.new do - - session_new.batch do - feeds_to_publish.each {|one| - publishing(one[:user_from],one[:user_to],one[:main_message],Feed_action,FB_app_link + "/?f=#{FROM_FEEDS}",processing_phraze(@today_question.feedtext1, @user_local.first_name, self_publishing,@user_local.gender,user_names.size ) ,FB_app_link + "/?f=#{FROM_FEEDS}",processing_phraze(@today_question.feedtext2, @user_local.first_name, self_publishing,@user_local.gender,user_names.size ),'image',Current_site + @today_question.feedpic.url(:normal),FB_app_link + "/?f=#{FROM_FEEDS}") - } - #session batch + + + begin + timeout 10 do + session_new.batch do + feeds_to_publish.each {|one| + publishing(one[:user_from],one[:user_to],one[:main_message],Feed_action,FB_app_link + "/?f=#{FROM_FEEDS}",processing_phraze(@today_question.feedtext1, @user_local.first_name, self_publishing,@user_local.gender,user_names.size ) ,FB_app_link + "/?f=#{FROM_FEEDS}",processing_phraze(@today_question.feedtext2, @user_local.first_name, self_publishing,@user_local.gender,user_names.size ),'image',Current_site + @today_question.feedpic.url(:normal),FB_app_link + "/?f=#{FROM_FEEDS}") + } + #session batch + end + time_counter ("Session batch") + end + rescue TimeoutError + Rails.logger.warn " >" * 15 + Rails.logger.warn " TIMEOUT FOR PUBLISHING " + Rails.logger.warn " >" * 15 end - time_counter ("Session batch") + + #thread end end debug_message scenario_themself diff --git a/online/app/views/user/facebook_error.erb b/online/app/views/user/facebook_error.erb index e35baba..c742e1d 100644 --- a/online/app/views/user/facebook_error.erb +++ b/online/app/views/user/facebook_error.erb @@ -1,7 +1,7 @@

- Sorry, but there are not enough data to show something to you. + Sorry, but facebook does not work correctly now.
-- 2.11.4.GIT