From 339a7307794b47e816eb916754c474ca2955b262 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 4 Nov 2012 12:01:03 -0600 Subject: [PATCH] timeout on background jobs --- app/models/asset_image_conversion_request.rb | 9 +++++++-- app/models/outfit_image_update.rb | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/asset_image_conversion_request.rb b/app/models/asset_image_conversion_request.rb index 0b864b61..a2771321 100644 --- a/app/models/asset_image_conversion_request.rb +++ b/app/models/asset_image_conversion_request.rb @@ -1,6 +1,9 @@ require 'resque-retry' +require 'timeout' class AssetImageConversionRequest + TIMEOUT_IN_SECONDS = 30 + extend Resque::Plugins::Retry @retry_limit = 5 @@ -9,8 +12,10 @@ class AssetImageConversionRequest @queue = :requested_asset_images def self.perform(asset_id) - asset = SwfAsset.find(asset_id) - asset.convert_swf_if_not_converted! + Timeout::timeout(TIMEOUT_IN_SECONDS) do + asset = SwfAsset.find(asset_id) + asset.convert_swf_if_not_converted! + end end class OnCreation < AssetImageConversionRequest diff --git a/app/models/outfit_image_update.rb b/app/models/outfit_image_update.rb index 59364fb4..2fc4bc5b 100644 --- a/app/models/outfit_image_update.rb +++ b/app/models/outfit_image_update.rb @@ -1,8 +1,14 @@ +require 'timeout' + class OutfitImageUpdate + TIMEOUT_IN_SECONDS = 30 + @queue = :outfit_image_updates def self.perform(id) - Outfit.find(id).write_image! + Timeout::timeout(TIMEOUT_IN_SECONDS) do + Outfit.find(id).write_image! + end end # Represents an outfit image update for an outfit that existed before this