Class: ScriptCore::ServiceProcess
- Defined in:
- lib/script_core/service_process.rb
Instance Attribute Summary collapse
-
#environment_variables ⇒ Object
readonly
Returns the value of attribute environment_variables.
-
#instruction_quota ⇒ Object
readonly
Returns the value of attribute instruction_quota.
-
#instruction_quota_start ⇒ Object
readonly
Returns the value of attribute instruction_quota_start.
-
#memory_quota ⇒ Object
readonly
Returns the value of attribute memory_quota.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#spawner ⇒ Object
readonly
Returns the value of attribute spawner.
Instance Method Summary collapse
-
#initialize(path, spawner, instruction_quota, instruction_quota_start, memory_quota, environment_variables = {}) ⇒ ServiceProcess
constructor
A new instance of ServiceProcess.
- #open ⇒ Object
Constructor Details
#initialize(path, spawner, instruction_quota, instruction_quota_start, memory_quota, environment_variables = {}) ⇒ ServiceProcess
Returns a new instance of ServiceProcess.
7 8 9 10 11 12 13 14 |
# File 'lib/script_core/service_process.rb', line 7 def initialize(path, spawner, instruction_quota, instruction_quota_start, memory_quota, environment_variables = {}) @path = path @spawner = spawner @instruction_quota = instruction_quota @instruction_quota_start = instruction_quota_start @memory_quota = memory_quota @environment_variables = environment_variables end |
Instance Attribute Details
#environment_variables ⇒ Object (readonly)
Returns the value of attribute environment_variables.
5 6 7 |
# File 'lib/script_core/service_process.rb', line 5 def environment_variables @environment_variables end |
#instruction_quota ⇒ Object (readonly)
Returns the value of attribute instruction_quota.
5 6 7 |
# File 'lib/script_core/service_process.rb', line 5 def instruction_quota @instruction_quota end |
#instruction_quota_start ⇒ Object (readonly)
Returns the value of attribute instruction_quota_start.
5 6 7 |
# File 'lib/script_core/service_process.rb', line 5 def instruction_quota_start @instruction_quota_start end |
#memory_quota ⇒ Object (readonly)
Returns the value of attribute memory_quota.
5 6 7 |
# File 'lib/script_core/service_process.rb', line 5 def memory_quota @memory_quota end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/script_core/service_process.rb', line 5 def path @path end |
#spawner ⇒ Object (readonly)
Returns the value of attribute spawner.
5 6 7 |
# File 'lib/script_core/service_process.rb', line 5 def spawner @spawner end |
Instance Method Details
#open ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/script_core/service_process.rb', line 16 def open in_reader, in_writer = IO.pipe out_reader, out_writer = IO.pipe pid = spawner.spawn( environment_variables, path, "-i", instruction_quota.to_s, "-C", instruction_quota_start.to_s, "-m", memory_quota.to_s, in: in_reader, out: out_writer, unsetenv_others: true ) in_reader.close out_writer.close in_writer.binmode out_reader.binmode begin yield ScriptCore::ServiceChannel.new(in_writer, out_reader) ensure code = spawner.wait(pid, Process::WNOHANG) || begin begin spawner.kill(9, pid) spawner.wait(pid) rescue Errno::ESRCH -1 end end out_reader.close in_writer.close end code end |