現在、私はrails 3.1 rc4で動作しており、ラックスペースサーバの作成をキューに入れるためにredisとresqueを使用しています。変数を設定するためにResqueとredisを待ちます
私が使用しているラックスペースの宝石である、cloudserversは、サーバがいつステータスメソッドでセットアップされたかを伝えます。
私が以下のコードで行っているのは、サーバがアクティブで使用可能な状態になった後にのみ、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文を助けますか?また、これはタスクをキューに入れることができないように思えます。 サーバーの準備ができているかどうかを確認するだけの新しいタスクをエンキューする必要がありますか?
ありがとうございました!