Class: Jackal::Utils::Process
- Inherits:
-
Object
- Object
- Jackal::Utils::Process
- Defined in:
- lib/jackal/utils/process.rb
Constant Summary collapse
- DEFAULT_STORAGE_DIRECTORY =
Default path for IO tmp files
'/tmp/jackal-process-manager'
- BLACKLISTED_ENV =
Environment variables that should be removed from process environment
['GIT_DIR']
Instance Attribute Summary collapse
-
#configuration ⇒ Smash
readonly
Manager configuration.
-
#storage_directory ⇒ String
readonly
Storage directory path.
Instance Method Summary collapse
-
#create_io_tmp(*args) ⇒ IO
Temporary IO for logging.
-
#initialize(config = {}) ⇒ self
constructor
Create new instance.
-
#process(identifier, *command) {|| ... } ⇒ ChildProcess
Create new process.
Constructor Details
#initialize(config = {}) ⇒ self
Create new instance
26 27 28 29 30 31 32 33 |
# File 'lib/jackal/utils/process.rb', line 26 def initialize(config={}) @base_env = ENV.to_hash @configuration = config.to_smash @storage_directory = configuration.fetch( :storage_directory, DEFAULT_STORAGE_DIRECTORY ) FileUtils.mkdir_p(storage_directory) end |
Instance Attribute Details
#configuration ⇒ Smash (readonly)
Returns manager configuration.
18 19 20 |
# File 'lib/jackal/utils/process.rb', line 18 def configuration @configuration end |
#storage_directory ⇒ String (readonly)
Returns storage directory path.
20 21 22 |
# File 'lib/jackal/utils/process.rb', line 20 def storage_directory @storage_directory end |
Instance Method Details
#create_io_tmp(*args) ⇒ IO
Temporary IO for logging
66 67 68 69 70 71 72 |
# File 'lib/jackal/utils/process.rb', line 66 def create_io_tmp(*args) path = File.join(storage_directory, args.join('-')) FileUtils.mkdir_p(File.dirname(path)) t_file = File.open(path, 'w+') t_file.sync t_file end |
#process(identifier, *command) {|| ... } ⇒ ChildProcess
Create new process
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jackal/utils/process.rb', line 41 def process(identifier, *command) _proc = nil if(command.size == 1) command = Shellwords.shellsplit(command.first) end if(block_given?) if(configuration[:spawn]) _proc = clean_env!{ ChildProcess::Unix::PosixSpawnProcess.new(command) } scrub_env(_proc.environment) clean_env!{ yield _proc } else _proc = clean_env!{ ChildProcess.build(*command) } scrub_env(_proc.environment) clean_env!{ yield _proc } end else raise ArgumentError.new('Expecting block but no block provided!') end _proc end |