There is no direct support for setting up a connection to SimpleDB in SimpleWorker (yet), but it's very easy to do. In this example we'll be using SimpleRecord (and you should too). Let's define our Amazon Web Services (AWS) access keys in the SimpleWorker global configuration: SimpleWorker.configure do |config|
config.access_key = "ACCESS_KEY"
config.secret_key = "SECRET_KEY"
config.global_attributes[:aws_access_key] = 'my_aws_access_key'
config.global_attributes[:aws_secret_key] = 'my_aws_secret_key'
end
Then in our worker, we just add a single line: SimpleRecord.establish_connection(aws_access_key, aws_secret_key, {:connection_mode => :single})
So a full example might be: class MyWorker < SimpleWorker::Base
def run
SimpleRecord.establish_connection(aws_access_key, aws_secret_key, {:connection_mode => :single})
# And now just access your data like normal
@users = User.find(:all)
# Do more stuff here with your users
end
end
|
|