Module: FireAndForget::Launcher
- Included in:
- FireAndForget
- Defined in:
- lib/fire_and_forget/launcher.rb
Instance Method Summary collapse
-
#[](task_name) ⇒ Object
Gets the TaskDescription of a task.
-
#add_task(task_name, path_to_binary, niceness = 0, default_params = {}, env = {}) ⇒ Object
Registers a task and makes it available for easy launching using #fire.
-
#binary(task_name) ⇒ String
Returns the path to the binary for the given task.
-
#fire(task_name, params = {}) ⇒ Object
Launches the given task.
-
#get_pid(task_name) ⇒ Object
(also: #pid)
Retrieve the PID of the running task given by task_name.
-
#get_status(task_name) ⇒ String
Get the status for the given task.
-
#int(task_name) ⇒ Object
Sends a running task the INT signal.
-
#kill(task_name, signal = "TERM") ⇒ Object
Sends a running task an arbitrary signal.
-
#map_pid(task_name, pid) ⇒ Object
(also: #set_pid)
Used by the Daemon module to set the correct PID for a given task.
-
#set_status(task_name, status) ⇒ Object
Sets the status of the given task enabling simple interprocess communication through string messages.
- #tasks ⇒ Object
-
#term(task_name) ⇒ Object
Sends a running task the TERM signal.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
Catch method missing to enable launching of tasks by direct name e.g.
FireAndForget.add_task(:process_things, "/usr/bin/process")
launch this task:
FireAndForget.process_things
122 123 124 125 126 127 128 |
# File 'lib/fire_and_forget/launcher.rb', line 122 def method_missing(method, *args, &block) if tasks.key?(method) fire(method, *args, &block) else super end end |
Instance Method Details
#[](task_name) ⇒ Object
Gets the TaskDescription of a task
42 43 44 |
# File 'lib/fire_and_forget/launcher.rb', line 42 def [](task_name) tasks[task_name] end |
#add_task(task_name, path_to_binary, niceness = 0, default_params = {}, env = {}) ⇒ Object
Registers a task and makes it available for easy launching using #fire
27 28 29 |
# File 'lib/fire_and_forget/launcher.rb', line 27 def add_task(task_name, path_to_binary, niceness=0, default_params={}, env={}) tasks[task_name] = TaskDescription.new(task_name, path_to_binary, niceness, default_params, env) end |
#binary(task_name) ⇒ String
Returns the path to the binary for the given task
35 36 37 |
# File 'lib/fire_and_forget/launcher.rb', line 35 def binary(task_name) tasks[task_name].binary end |
#fire(task_name, params = {}) ⇒ Object
Launches the given task
54 55 56 57 58 |
# File 'lib/fire_and_forget/launcher.rb', line 54 def fire(task_name, params={}) task = tasks[task_name] command = Command::Fire.new(task, params) Client.run(command) end |
#get_pid(task_name) ⇒ Object Also known as: pid
Retrieve the PID of the running task given by task_name
87 88 89 90 |
# File 'lib/fire_and_forget/launcher.rb', line 87 def get_pid(task_name) command = Command::GetPid.new(task_name) Client.run(command) end |
#get_status(task_name) ⇒ String
Get the status for the given task
74 75 76 77 |
# File 'lib/fire_and_forget/launcher.rb', line 74 def get_status(task_name) command = Command::GetStatus.new(task_name) Client.run(command) end |
#int(task_name) ⇒ Object
Sends a running task the INT signal
99 100 101 |
# File 'lib/fire_and_forget/launcher.rb', line 99 def int(task_name) kill(task_name, "INT") end |
#kill(task_name, signal = "TERM") ⇒ Object
Sends a running task an arbitrary signal
109 110 111 112 |
# File 'lib/fire_and_forget/launcher.rb', line 109 def kill(task_name, signal="TERM") command = Command::Kill.new(task_name, signal) Client.run(command) end |
#map_pid(task_name, pid) ⇒ Object Also known as: set_pid
Used by the Daemon module to set the correct PID for a given task
80 81 82 83 |
# File 'lib/fire_and_forget/launcher.rb', line 80 def map_pid(task_name, pid) command = Command::SetPid.new(task_name, pid) Client.run(command) end |
#set_status(task_name, status) ⇒ Object
Sets the status of the given task enabling simple interprocess communication through string messages
64 65 66 67 |
# File 'lib/fire_and_forget/launcher.rb', line 64 def set_status(task_name, status) command = Command::SetStatus.new(task_name, status) Client.run(command) end |
#tasks ⇒ Object
46 47 48 |
# File 'lib/fire_and_forget/launcher.rb', line 46 def tasks @tasks ||= {} end |
#term(task_name) ⇒ Object
Sends a running task the TERM signal
94 95 96 |
# File 'lib/fire_and_forget/launcher.rb', line 94 def term(task_name) kill(task_name, "TERM") end |