forked from robertzx/simple_worker_examples
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1. Edit carrierwave.yml and fill in your SimpleWorker and AWS information. Make sure that AWS S3 bucket exists. | ||
2. Run "ruby carrierwave_worker_init.rb" - this will upload image to S3, so worker will have something to work with, and will create simple html page with link to uploaded image. | ||
3. Finally, run "ruby carrierwave_worker_runner.rb", wait worker to finish and refresh html page. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sw: | ||
project_id: | ||
token: | ||
|
||
aws: | ||
access_key: | ||
secret_key: | ||
bucket: | ||
|
||
file_name: simple-worker.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def carrierwave_configure(aws_access_key, aws_secret_key, aws_bucket) | ||
CarrierWave.configure do |config| | ||
config.fog_credentials = { | ||
:provider => 'AWS', | ||
:aws_access_key_id => aws_access_key, | ||
:aws_secret_access_key => aws_secret_key | ||
} | ||
|
||
config.fog_directory = aws_bucket | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'simple_worker' | ||
|
||
class CarrierWaveWorker < SimpleWorker::Base | ||
require 'RMagick' # it's available at SimpleWorker servers | ||
|
||
merge_gem 'carrierwave' | ||
# if you need ActiveRecord support, use following line instead | ||
# merge_gem 'carrierwave', :require => ['carrierwave', 'carrierwave/orm/activerecord'] | ||
|
||
merge_gem 'fog' | ||
|
||
merge 'sample_uploader' | ||
merge 'carrierwave_configure' | ||
|
||
attr_accessor :aws_access_key | ||
attr_accessor :aws_secret_key | ||
attr_accessor :aws_bucket | ||
attr_accessor :file_name | ||
|
||
def run | ||
carrierwave_configure(@aws_access_key, @aws_secret_key, @aws_bucket) | ||
uploader = SampleUploader.new | ||
|
||
uploader.retrieve_from_store!(@file_name) | ||
uploader.cache_stored_file! | ||
|
||
i = Magick::ImageList.new(uploader.file.path) | ||
ri = i.rotate(90) | ||
ri.write(@file_name) | ||
|
||
uploader.store!(File.new(@file_name)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'yaml' | ||
require 'carrierwave' | ||
require 'fog' | ||
|
||
require_relative 'sample_uploader' | ||
require_relative 'carrierwave_configure' | ||
|
||
conf = YAML.load_file 'carrierwave.yml' | ||
carrierwave_configure(conf['aws']['access_key'], conf['aws']['secret_key'], conf['aws']['bucket']) | ||
|
||
uploader = SampleUploader.new | ||
uploader.store!(File.new(conf['file_name'])) | ||
|
||
File.open("look-at-me.html", "w") do |f| | ||
f.puts "<img src=\"#{uploader.url}\" />" | ||
end | ||
|
||
puts "now open look-at-me.html in browser" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'yaml' | ||
require 'carrierwave' # must be available at queue time | ||
|
||
require_relative 'carrierwave_worker' | ||
|
||
conf = YAML.load_file 'carrierwave.yml' | ||
|
||
SimpleWorker.configure do |config| | ||
config.project_id = conf['sw']['project_id'] | ||
config.token = conf['sw']['token'] | ||
end | ||
|
||
worker = CarrierWaveWorker.new | ||
|
||
worker.aws_access_key = conf['aws']['access_key'] | ||
worker.aws_secret_key = conf['aws']['secret_key'] | ||
worker.aws_bucket = conf['aws']['bucket'] | ||
worker.file_name = conf['file_name'] | ||
|
||
worker.queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class SampleUploader < CarrierWave::Uploader::Base | ||
storage :fog | ||
end |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.