ManageIQ / more_core_extensions

MoreCoreExtensions are a set of core extensions beyond those provided by ActiveSupport.
MIT License
5 stars 23 forks source link

Add custom pause, resume and alive? Process methods #73

Closed djberg96 closed 4 years ago

djberg96 commented 4 years ago

This PR extends the Process module to include pause, resume and alive? methods.

The Unix implementation is fairly straightforward, simply using SIGSTOP and SIGCONT. The Windows implementation was trickier, and required the use of an ffi wrapper (here I used fiddle from the standard library).

WIP for now until I add some specs. But, I can tell you that in local examples it worked as expected.

The only quirk I noticed was on Windows it would not immediately respond to an event, e.g. SIGINT, but would instead defer until the process was resumed, whereas on unixy systems it appeared to react immediately, e.g. you could ctrl-c out of a paused process. But, I couldn't tell you if one of these is more "correct" than the other.

The ultimate goal is to remove the custom MiqProcess module from gems-pending.

Fryguy commented 4 years ago

@bdunne Thoughts?

djberg96 commented 4 years ago

@Fryguy ok, updated readme.

Fryguy commented 4 years ago

Looks good @djberg96 ... I think we are just waiting on specs.

djberg96 commented 4 years ago

@Fryguy, @NickLaMuro suggestions for testing an external process?

NickLaMuro commented 4 years ago

suggestions for testing an external process?

🤔

This is the best I can come up with at the moment...

djberg96 commented 4 years ago

@NickLaMuro I don't know if it's an option, but I did see this: https://github.com/jpastuszek/rspec-background-process

djberg96 commented 4 years ago

@NickLaMuro Ok, I've add some specs, please let me know what you think.

Note that while I did insert some code to make the Windows version cross-platform, the current specs do not currently pass on Windows. This is because getting process status information on Windows is more difficult.

There is a status field in the Win32_Process object, but unfortunately it's always null (as per the documentation). On Windows you can't get process status, you can only get thread status. While it's possible to get this information, it would require adding more code to sys-proctable, which I don't want to worry about right now, especially since Windows doesn't matter to us atm.

djberg96 commented 4 years ago

@miq-bot remove_label wip

djberg96 commented 4 years ago

@NickLaMuro, @Fryguy, @jrafanie I think it's ready to go. :)

miq-bot commented 4 years ago

Checked commits https://github.com/djberg96/more_core_extensions/compare/e8f0676bf9e36b3955f03286bd94ed403f5d5217~...7cad6e57c775867349da5cee1bda8b7df7388f00 with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 4 files checked, 3 offenses detected

spec/core_ext/process/pause_resume_spec.rb