Chapter 18. Processing Multiple Actions
In this chapter, we’re going to expand our agent and client to handle multiple distinct actions. This adds just one small layer on what you already know, but it provides you great flexibility in how you build and package your agents going forward.
Recalling what you learned in Chapter 15, go back and open up thanks/agent/thanks.rb to add another action. Let’s call this new action get_towel. Add it just after the very first end so it will remain inside the Thanks class. You can put anything you want in this new action (just remember to set a message and a statuscode):
module MCollective
module Agent
class Thanks<RPC::Agent
action "say_goodbye" do
blah blah blah
end
action "get_towel" do
something amazing
end
end
end
end
Next, we need to update the DDL file to know about the new action. Do yourself a favor and copy/paste the entire action block for say_goodbye and then edit the title. Change your input and output for whatever amazing thing you’ve done with the get_towel action:
action "say_goodbye", :description => "Says Goodbye" doblah blah blahend action "get_towel", :description => "Grabs Towel" do display :always # could be :ok or :failed input :color, :prompt => "Which color towel to grab",amazing inputsend
That was all pretty easy, right? Now let’s get dirty with the only nontrivial bit of supporting multiple actions, which is adding multiaction smarts into your application. Open up the thanks/application/thanks.rb file and ...