Module: Rya::CoreExtensions::Process
- Includes:
- Time
- Defined in:
- lib/rya/core_extensions.rb
Instance Method Summary collapse
-
#run_and_time_it!(title = "", cmd = "", logger = Rya::AbortIf::logger, run: true, &b) ⇒ Object
Run a command and time it as well!.
-
#run_it(*a, &b) ⇒ Object
Runs a command and outputs stdout and stderr.
-
#run_it!(*a, &b) ⇒ Object
Like run_it() but will raise Rya::AbortIf::Exit on non-zero exit status.
-
#run_until_success(max_attempts) { ... } ⇒ Integer
I run your program until it succeeds or I fail too many times.
Methods included from Time
Instance Method Details
#run_and_time_it!(title = "", cmd = "", logger = Rya::AbortIf::logger, run: true, &b) ⇒ Object
Note:
The ‘run’ keyword argument is nice if you have some big pipeline and you need to temporarily prevent sections of the code from running.
Run a command and time it as well!
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/rya/core_extensions.rb', line 243 def run_and_time_it! title = "", cmd = "", logger = Rya::AbortIf::logger, run: true, &b time_it title, logger, run: run do Rya::AbortIf.logger.debug { "Running: #{cmd}" } run_it! cmd, &b end end |
#run_it(*a, &b) ⇒ Object
Runs a command and outputs stdout and stderr
197 198 199 200 201 202 203 204 |
# File 'lib/rya/core_extensions.rb', line 197 def run_it *a, &b exit_status, stdout, stderr = systemu *a, &b puts stdout unless stdout.empty? STDERR.puts stderr unless stderr.empty? exit_status end |
#run_it!(*a, &b) ⇒ Object
Like run_it() but will raise Rya::AbortIf::Exit on non-zero exit status.
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/rya/core_extensions.rb', line 207 def run_it! *a, &b exit_status = self.run_it *a, &b # Sometimes, exited? is not true and there will be no exit # status. Success should catch all failures. Rya::AbortIf.abort_unless exit_status.success?, "Command failed with status " \ "'#{exit_status.to_s}' " \ "when running '#{a.inspect}', " \ "'#{b.inspect}'" exit_status end |
#run_until_success(max_attempts) { ... } ⇒ Integer
I run your program until it succeeds or I fail too many times.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/rya/core_extensions.rb', line 179 def run_until_success max_attempts, &block max_attempts.times do |attempt_index| proc_status = yield block unless proc_status.respond_to? :exitstatus raise Rya::Error, "The block did not return an object that responds to exitstatus" end if proc_status.exitstatus.zero? return attempt_index + 1 end end raise Rya::MaxAttemptsExceededError, "max_attempts exceeded" end |