Permalink
Browse files

Use girl_friday to queue archive tasks.

  • Loading branch information...
1 parent a1e2d0f commit 1d811a6e8ee40ba3e4f077cf6431af4188d2bf0f @gmanley committed Apr 22, 2012
Showing with 22 additions and 2 deletions.
  1. +5 −0 Gemfile
  2. +4 −0 Gemfile.lock
  3. +6 −2 app/models/album.rb
  4. +3 −0 config/application.rb
  5. +4 −0 config/initializers/girl_friday.rb
View
@@ -35,6 +35,11 @@ gem 'mini_magick', git: 'git://github.com/gmanley/mini_magick.git', branch: 'gra
gem 'fog'
gem 'archive-zip', git: 'git://github.com/javanthropus/archive-zip.git'
+gem 'girl_friday'
+
+# Use this, unicorn or raibows in production for girl_friday
+# gem 'puma', group: :production
+
group :development do
gem 'thin'
gem 'guard'
View
@@ -80,6 +80,7 @@ GEM
coffeebeans (1.0.1)
actionpack (>= 3.0.0)
coffee-script
+ connection_pool (0.1.0)
daemons (1.1.8)
database_cleaner (0.7.2)
devise (2.0.4)
@@ -107,6 +108,8 @@ GEM
nokogiri (~> 1.5.0)
ruby-hmac
formatador (0.2.1)
+ girl_friday (0.9.7)
+ connection_pool (~> 0.1.0)
growl (1.0.3)
guard (1.0.1)
ffi (>= 0.5.0)
@@ -275,6 +278,7 @@ DEPENDENCIES
fabrication
ffaker
fog
+ girl_friday
growl
guard
guard-rspec
View
@@ -11,8 +11,12 @@ def set_thumbnail_url
update_attribute(:thumbnail_url, images.sample.image_url(:thumb)) unless images.empty?
end
+ def add_to_archive_queue!
+ ALBUM_ARCHIVE_QUEUE.push(id.to_s)
+ end
+
def archive!
- zip_temp_file = Tempfile.new([self.id.to_s, '.zip'], encoding: 'binary')
+ zip_temp_file = Tempfile.new(id.to_s, encoding: 'binary')
Archive::Zip.open(zip_temp_file, :w) do |zip|
images.each do |image_record|
image = image_record.image
@@ -31,4 +35,4 @@ def archive!
ensure
zip_temp_file.close if zip_temp_file
end
-end
+end
View
@@ -22,6 +22,9 @@ class Application < Rails::Application
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+ # Enable threaded mode for girl_friday
+ config.threadsafe!
+
# Enable the asset pipeline
config.assets.enabled = true
@@ -0,0 +1,4 @@
+ALBUM_ARCHIVE_QUEUE = GirlFriday::WorkQueue.new(:album_archive_queue) do |album_id|
+ album = Album.find(album_id)
+ album.archive!
+end

0 comments on commit 1d811a6

Please sign in to comment.