Class: Naf::ApplicationType
- Defined in:
- app/models/naf/application_type.rb
Constant Summary collapse
- SCRIPT_RUNNER =
"#{Gem.ruby} #{Rails.root}/script/rails runner"
- JOB_LOGGER =
"#{Rails.root}/script/rails runner ::Process::Naf::Logger::JobLog.run"
Class Method Summary collapse
Instance Method Summary collapse
- #bash_command_invocator(job) ⇒ Object
- #bash_script_invocator(job) ⇒ Object
-
#invoke(job, job_command) ⇒ Object
This method calls Process.spawn to excute a built command.
- #rails_invocator(job) ⇒ Object
- #ruby_script_invocator(job) ⇒ Object
-
#spawn(job) ⇒ Object
————————- *** Instance Methods *** +++++++++++++++++++++++++.
Methods inherited from NafBase
Class Method Details
.bash_command ⇒ Object
71 72 73 |
# File 'app/models/naf/application_type.rb', line 71 def self.bash_command @bash_command ||= find_by_script_type_name('bash command') end |
.bash_script ⇒ Object
75 76 77 |
# File 'app/models/naf/application_type.rb', line 75 def self.bash_script @bash_script ||= find_by_script_type_name('bash script') end |
.rails ⇒ Object
63 64 65 |
# File 'app/models/naf/application_type.rb', line 63 def self.rails @rails ||= find_by_script_type_name('rails') end |
.ruby ⇒ Object
67 68 69 |
# File 'app/models/naf/application_type.rb', line 67 def self.ruby @ruby ||= find_by_script_type_name('ruby') end |
Instance Method Details
#bash_command_invocator(job) ⇒ Object
51 52 53 |
# File 'app/models/naf/application_type.rb', line 51 def bash_command_invocator(job) invoke(job, job.command) end |
#bash_script_invocator(job) ⇒ Object
55 56 57 |
# File 'app/models/naf/application_type.rb', line 55 def bash_script_invocator(job) invoke(job, job.command) end |
#invoke(job, job_command) ⇒ Object
This method calls Process.spawn to excute a built command. The first part of the command is the execution of the job command, redirecting stderr to stdout. Stdout and stderr are then sent through a pipe to be used as input for the job logger. The job logger will also redirect stderr to stdout, and save any crash logs. At the end of the built command, there is a exit $PIPESTATUS command that will return the exit status of the whole command.
42 43 44 45 |
# File 'app/models/naf/application_type.rb', line 42 def invoke(job, job_command) command = job_command + " 2>&1 | #{JOB_LOGGER} >> #{LOGGING_ROOT_DIRECTORY}/naf/crash.log 2>&1; exit $PIPESTATUS" Process.spawn({ 'NAF_JOB_ID' => job.id.to_s }, command) end |
#rails_invocator(job) ⇒ Object
47 48 49 |
# File 'app/models/naf/application_type.rb', line 47 def rails_invocator(job) invoke(job, SCRIPT_RUNNER + " " + job.command) end |
#ruby_script_invocator(job) ⇒ Object
59 60 61 |
# File 'app/models/naf/application_type.rb', line 59 def ruby_script_invocator(job) invoke(job, job.command) end |
#spawn(job) ⇒ Object
*** Instance Methods *** +++++++++++++++++++++++++
32 33 34 |
# File 'app/models/naf/application_type.rb', line 32 def spawn(job) self.send(invocation_method.to_sym, job) end |