timeout on background jobs
This commit is contained in:
parent
07f49307f1
commit
339a730779
2 changed files with 14 additions and 3 deletions
|
@ -1,6 +1,9 @@
|
||||||
require 'resque-retry'
|
require 'resque-retry'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
class AssetImageConversionRequest
|
class AssetImageConversionRequest
|
||||||
|
TIMEOUT_IN_SECONDS = 30
|
||||||
|
|
||||||
extend Resque::Plugins::Retry
|
extend Resque::Plugins::Retry
|
||||||
|
|
||||||
@retry_limit = 5
|
@retry_limit = 5
|
||||||
|
@ -9,9 +12,11 @@ class AssetImageConversionRequest
|
||||||
@queue = :requested_asset_images
|
@queue = :requested_asset_images
|
||||||
|
|
||||||
def self.perform(asset_id)
|
def self.perform(asset_id)
|
||||||
|
Timeout::timeout(TIMEOUT_IN_SECONDS) do
|
||||||
asset = SwfAsset.find(asset_id)
|
asset = SwfAsset.find(asset_id)
|
||||||
asset.convert_swf_if_not_converted!
|
asset.convert_swf_if_not_converted!
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class OnCreation < AssetImageConversionRequest
|
class OnCreation < AssetImageConversionRequest
|
||||||
@retry_limit = 5
|
@retry_limit = 5
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
class OutfitImageUpdate
|
class OutfitImageUpdate
|
||||||
|
TIMEOUT_IN_SECONDS = 30
|
||||||
|
|
||||||
@queue = :outfit_image_updates
|
@queue = :outfit_image_updates
|
||||||
|
|
||||||
def self.perform(id)
|
def self.perform(id)
|
||||||
|
Timeout::timeout(TIMEOUT_IN_SECONDS) do
|
||||||
Outfit.find(id).write_image!
|
Outfit.find(id).write_image!
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Represents an outfit image update for an outfit that existed before this
|
# Represents an outfit image update for an outfit that existed before this
|
||||||
# feature was built. Its queue has a lower priority, so new outfits will
|
# feature was built. Its queue has a lower priority, so new outfits will
|
||||||
|
|
Loading…
Reference in a new issue