現在、私はRails 3.1 rc4で実行しており、ラックスペースサーバーの作成をキューに入れるためにredisとresqueを使用しています。
私が使用しているrackspacegemであるcloudserversは、サーバーがstatusメソッドでセットアップされたときに通知します。
以下のコードで私がやろうとしているのは、サーバーがアクティブで使用できる状態になった後でのみ、elsifでコードを実行することです。
class ServerGenerator
@queue = :servers_queue
def self.perform(current_id)
current_user = User.find(current_id)
cs = CloudServers::Connection.new(:username => "***blocked for security***", :api_key => "***blocked for security***")
image = cs.get_image(49) # Set the linux distro
flavor = cs.get_flavor(1) # Use the 256 Mb of Ram instance
newserver = cs.create_server(:name => "#{current_user.name}", :imageId => image.id, :flavorId => flavor.id)
if newserver.status == "BUILD"
newserver.refresh
elsif newserver.status == "ACTIVE"
# Do stuff here, I generated another server with a different, static name
# so that I could see if it was working
cs = CloudServers::Connection.new(:username => "***blocked for security***", :api_key => "***blocked for security***")
image = cs.get_image(49)
flavor = cs.get_flavor(1)
newserver = cs.create_server(:name => "working", :imageId => image.id, :flavorId => flavor.id)
end
end
end
上記を実行すると、名前として「current_user.name」を使用する最初のサーバーのみが生成されました。ループはifステートメントの周りに役立ちますか?また、これはタスクをキューに入れるには不十分な方法のようです。サーバーの準備ができているかどうかを確認するだけの新しいタスクをキューに入れる必要がありますか?
本当にありがとう!