Skip to content

Child process queue workers #450

New issue

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

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

Already on ? Sign in to your account

Merged
merged 6 commits into from
Dec 29, 2024
Merged

Conversation

XbNz
Copy link
Contributor

@XbNz XbNz commented Dec 23, 2024

Commits related to feature discussed in #443

Note

nativephp/electron must be updated to remove javascript-side queue system

  • Remove ShouldBroadcast in favor of ShouldBroadcastNow in Events\\ChildProcess namespace

  • Implement QueueWorker::class

  • Add new binding to NativeServiceProvider::class

  • Fire up workers: iterate through queue worker config in NativeServiceProvider::configureApp()

  • Test QueueWorker::up(), QueueWorker::down()

  • Test QueueWorkerFake::class assertions work as expected

- Remove `ShouldBroadcast` in favor of `ShouldBroadcastNow` in `Events\\ChildProcess` namespace
- Implement `QueueWorker::class`
- Add new binding to `NativeServiceProvider::class`
- Fire up workers: iterate through queue worker config in `NativeServiceProvider::configureApp()`

- Test `QueueWorker::up()`, `QueueWorker::down()`
- Test `QueueWorkerFake::class` assertions work as expected
@SRWieZ
Copy link
Member

SRWieZ commented Dec 23, 2024

That was on my list of suggestions and changes I would like to see in Native PHP.

A quick look at it and everything seems fine to me.

I have a small suggestion to improve the developer experience for newcomers. We should add the command to the boot() method of the stub resources/stubs/NativeAppServiceProvider.php.stub:

// Launch the queue worker
QueueWorker::up()

Also a PR to update electron and another for the documentation.

When the PR for electron is available, I will gladly test it.

@XbNz
Copy link
Contributor Author

XbNz commented Dec 24, 2024

Electron PR is up: NativePHP/electron#149

I have a small suggestion to improve the developer experience for newcomers. We should add the command to the boot() method of the stub resources/stubs/NativeAppServiceProvider.php.stub:

// Launch the queue worker
QueueWorker::up()

QueueWorker::up() still requires a QueueConfig::class object to be passed in. As in here:

// NativeServiceProvider::class

protected function fireUpQueueWorkers(): void
{
    $queueConfigs = QueueConfig::fromConfigArray(config('nativephp.queue_workers'));

    foreach ($queueConfigs as $queueConfig) {
        $this->app->make(QueueWorkerContract::class)->up($queueConfig);
    }
}

Adding QueueWorker::up() alone to the published service provider won't work because it also needs a config. What I'm doing – and maybe there is a better way to do it, @simonhamp can chime in – is that after the bootstrapping is done, if the internal state indicates that the Electron app is active (nativephp-internal.running), I start up the workers.

Whether we should do this in NativeServiceProvider::class or NativeAppServiceProvider::class is probably a matter of taste. But in my opinion it's internal behavior that the user shouldn't need to be responsible for. If they want to disable queue workers, they can just provide an empty array to the queue_workers config key.

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.

Yep this looks great 👍🏼 I think it's right that we provide this functionality internally by default to save the developer having to think about setting workers up.

We should just make sure this works even when there is no queue_workers key in the config file (which is the state most apps will be in right now.

Once the docs are updated, I think this will be ready to go.

Great work @XbNz 🙏🏼

@XbNz
Copy link
Contributor Author

XbNz commented Dec 27, 2024

Documentation updated NativePHP/nativephp.com#69

@simonhampsimonhamp merged commit 101ddf0 into NativePHP:main Dec 29, 2024
21 checks passed
@simonhampsimonhamp mentioned this pull request Dec 29, 2024
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants