Skip to content

child process - sanity tests and tweaks #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gwleuverink
Copy link
Contributor

@gwleuverink gwleuverink commented Oct 25, 2024

Builds on #389

I started adding some tests. Will add some extra things to the ChildProcess api if that's okay with you @simonhamp.

  • Stub out tests
  • Set a cwd default if none was given
  • Add a ChildProcess::artisan() convenience method
  • Provide a way to make processes restart when they exit
  • Make sure the cmd argument accepts either a string or a array
  • Double check argument order to be consistent with other api's

@gwleuverink gwleuverink changed the title add some sanity tests child process - sanity tests and tweaks Oct 25, 2024
@simonhamp
Copy link
Member

I really like where this is going!

@gwleuverink
Copy link
Contributor Author

gwleuverink commented Oct 27, 2024

I've checked the argument order of existing existing API's for consistency.

The only component I found that refers to a runtime object on the electron process is Window.

Window::resize(400, 300, 'settings');

The order of arguments is mirrored to what we use for the ChildProcess.

ChildProcess::start('alias-for-child', 'sleep 10s');

Flipping those two arguments would be more consistent. And, now I think about it a bit more, the actual command also feels like the more important argument of the two.

Another option to consider is to use a fluent API instead. Most other components do something like the example below:

Dialog::new()
    ->title('Select a file')
    ->open();

Something similar could be achieved with ChildProcess, like we did with the proc_open experiment. But this may be overkill for this scenario. The operations on a process before and after starting it is quite limited.

$loop = ChildProcess::alias('main-loop')
    ->persistent()
    ->artisan('main-loop:start')
    ->message('send to stdin'); // race condition / nonsensical use-case?

My gut tells me to go with flipping the arguments. What do you think @simonhamp?

@gwleuverink
Copy link
Contributor Author

I can add the option to make a process restart when it exits somewhere here. Do you already have something for this on the electron side @simonhamp?

@simonhamp
Copy link
Member

Yep let's flip the args 👍🏼

I can add the option to make a process restart when it exits somewhere here. Do you already have something for this on the electron side @simonhamp?

Yes I do. I think we should let the Electron side handle this for now

@gwleuverink
Copy link
Contributor Author

I think that's it. Need to do some testing tonight to make sure this integrates with the persistent option on the electron side.

Will mark this as ready for review

@gwleuverink gwleuverink marked this pull request as ready for review October 29, 2024 11:23
@gwleuverink
Copy link
Contributor Author

If this is okay like this I'll start writing some documentation next

@simonhamp
Copy link
Member

Definitely! I've made a start on the docs here: NativePHP/nativephp.com#53

Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are great improvements. I think it just needs a little more to take it to the next level

@gwleuverink gwleuverink force-pushed the feature/child-processes branch from 9a50f74 to 8dbee1d Compare October 29, 2024 23:06
Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking excellent

@simonhamp simonhamp merged commit c1b46f4 into NativePHP:feature/child-processes Oct 31, 2024
1 check passed
@gwleuverink gwleuverink deleted the feature/child-processes branch October 31, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants