From e528d369299554b8fadc29a3d630d287fd704288 Mon Sep 17 00:00:00 2001 From: Adam Stanton Date: Mon, 17 Sep 2012 17:10:40 -0700 Subject: [PATCH 1/4] Add condition to check existence of remote_#{column}_url. This applies when determining whether to fire the background process. Sometimes you set the image in carrier wave using the remote_#{column}_url field if the source of the image is remote. This does not change the column field and hence #{column}_changed? is set to false and the job is never queued. --- .gitignore | 1 + lib/backgrounder/orm/mongoid.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 4040c6c1..c283382a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.gem +*.swp .bundle Gemfile.lock pkg/* diff --git a/lib/backgrounder/orm/mongoid.rb b/lib/backgrounder/orm/mongoid.rb index 095fa82d..23c9477f 100644 --- a/lib/backgrounder/orm/mongoid.rb +++ b/lib/backgrounder/orm/mongoid.rb @@ -10,7 +10,7 @@ def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_processing? - process_#{column}_upload != true && #{column}_changed? + process_#{column}_upload != true && (#{column}_changed? || remote_#{column}_url.empty? == false) end RUBY end @@ -20,7 +20,7 @@ def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_storage? - process_#{column}_upload != true && #{column}_changed? + process_#{column}_upload != true && (#{column}_changed? || remote_#{column}_url.empty? == false) end RUBY end @@ -30,4 +30,4 @@ def trigger_#{column}_background_storage? end # Backgrounder end # CarrierWave -Mongoid::Document::ClassMethods.send(:include, ::CarrierWave::Backgrounder::ORM::Mongoid) \ No newline at end of file +Mongoid::Document::ClassMethods.send(:include, ::CarrierWave::Backgrounder::ORM::Mongoid) From eb1fe4d0d7b76a78f4080b2523d8d69d91023f21 Mon Sep 17 00:00:00 2001 From: Adam Stanton Date: Mon, 17 Sep 2012 18:03:11 -0700 Subject: [PATCH 2/4] Add remote URL check to active record. Also call into super's trigger check to make it more DRYer. --- lib/backgrounder/orm/activerecord.rb | 4 ++-- lib/backgrounder/orm/mongoid.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/backgrounder/orm/activerecord.rb b/lib/backgrounder/orm/activerecord.rb index 75d2e26b..084c7235 100644 --- a/lib/backgrounder/orm/activerecord.rb +++ b/lib/backgrounder/orm/activerecord.rb @@ -13,7 +13,7 @@ def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_processing? - process_#{column}_upload != true && #{column}_changed? + super && (#{column}_changed? || remote_#{column}_url.empty? == false) end RUBY end @@ -23,7 +23,7 @@ def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_storage? - process_#{column}_upload != true && #{column}_changed? + super && (#{column}_changed? || remote_#{column}_url.empty? == false) end RUBY end diff --git a/lib/backgrounder/orm/mongoid.rb b/lib/backgrounder/orm/mongoid.rb index 23c9477f..fb967339 100644 --- a/lib/backgrounder/orm/mongoid.rb +++ b/lib/backgrounder/orm/mongoid.rb @@ -10,7 +10,7 @@ def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_processing? - process_#{column}_upload != true && (#{column}_changed? || remote_#{column}_url.empty? == false) + super && (#{column}_changed? || remote_#{column}_url.empty? == false) end RUBY end @@ -20,7 +20,7 @@ def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_storage? - process_#{column}_upload != true && (#{column}_changed? || remote_#{column}_url.empty? == false) + super && (#{column}_changed? || remote_#{column}_url.empty? == false) end RUBY end From de51916dfec11492bb96b5a013eaa8cb9286e9b3 Mon Sep 17 00:00:00 2001 From: Adam Stanton Date: Mon, 24 Sep 2012 12:26:51 -0700 Subject: [PATCH 3/4] Remove swp files from .gitignore as not everyone uses vim --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c283382a..4040c6c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.gem -*.swp .bundle Gemfile.lock pkg/* From 9cbf759cf6e8e6dc820a42c5a59a63d25a9693dd Mon Sep 17 00:00:00 2001 From: Adam Stanton Date: Mon, 24 Sep 2012 12:38:51 -0700 Subject: [PATCH 4/4] Use .present? instead of checking for non-empty string. --- lib/backgrounder/orm/activerecord.rb | 4 ++-- lib/backgrounder/orm/mongoid.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/backgrounder/orm/activerecord.rb b/lib/backgrounder/orm/activerecord.rb index 084c7235..23d75a7e 100644 --- a/lib/backgrounder/orm/activerecord.rb +++ b/lib/backgrounder/orm/activerecord.rb @@ -13,7 +13,7 @@ def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_processing? - super && (#{column}_changed? || remote_#{column}_url.empty? == false) + super && (#{column}_changed? || remote_#{column}_url.present?) end RUBY end @@ -23,7 +23,7 @@ def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_storage? - super && (#{column}_changed? || remote_#{column}_url.empty? == false) + super && (#{column}_changed? || remote_#{column}_url.present?) end RUBY end diff --git a/lib/backgrounder/orm/mongoid.rb b/lib/backgrounder/orm/mongoid.rb index fb967339..8be1bbef 100644 --- a/lib/backgrounder/orm/mongoid.rb +++ b/lib/backgrounder/orm/mongoid.rb @@ -10,7 +10,7 @@ def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_processing? - super && (#{column}_changed? || remote_#{column}_url.empty? == false) + super && (#{column}_changed? || remote_#{column}_url.present?) end RUBY end @@ -20,7 +20,7 @@ def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset) class_eval <<-RUBY, __FILE__, __LINE__ + 1 def trigger_#{column}_background_storage? - super && (#{column}_changed? || remote_#{column}_url.empty? == false) + super && (#{column}_changed? || remote_#{column}_url.present?) end RUBY end