Skip to content

Instantly share code, notes, and snippets.

@rorra
Created March 21, 2013 20:15
Show Gist options
  • Save rorra/5216306 to your computer and use it in GitHub Desktop.
Save rorra/5216306 to your computer and use it in GitHub Desktop.
S3 Random Issue
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