Created
March 21, 2013 20:15
-
-
Save rorra/5216306 to your computer and use it in GitHub Desktop.
S3 Random Issue
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
ENV["RACK_ENV"] ||= 'development' | |
EM.run do | |
connection = AMQP.connect(:host => '127.0.0.1') | |
puts "Connected to RabbitMQ. Running #{AMQP::VERSION} version of the gem..." | |
@@s3 = UberS3.new( | |
{ access_key: 'XXX', | |
secret_access_key: 'XXX', | |
bucket: "my-project-#{ENV['RACK_ENV']}", | |
adapter: :em_http_fibered | |
}) | |
channel = AMQP::Channel.new(connection) | |
exchange = channel.direct("my-channel") | |
queue = channel.queue("my-channel", durable: true).bind(exchange, routing_key: "my-key") | |
queue.subscribe do |payload| | |
Fiber.new { | |
message = JSON.parse(payload) | |
message['name'].delete!(' ') | |
o = UberS3::Object.new(@@s3.bucket, message['name'], Base64.decode64(message['content']), content_type: 'text/plain') | |
o.save | |
puts "#{message['name']} saved" | |
}.resume | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment