Skip to content
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

Removal of stopped worker which doesn't dispatch onStop #87

Open
chapterjason opened this issue Jun 8, 2024 · 2 comments
Open

Removal of stopped worker which doesn't dispatch onStop #87

chapterjason opened this issue Jun 8, 2024 · 2 comments

Comments

@chapterjason
Copy link

Hey nice bundle.

My workers will restart on file changes in development to reload the used resource inside the worker.
It looks like the onStop won't get triggered.

To overcome this, I created a command which I can use to clear the workers.
It looks like this:

    $onChange = debounce(static function () {
        run('docker compose stop xxx_worker');
        run ('docker compose exec xxx php bin/console messenger:monitor:purge:worker'); // Custom command as workaround
        run ('docker compose exec xxx php bin/console messenger:monitor:purge --older-than all'); // to only see new messages after reload
        run('docker compose start xxx_worker');
    }, 5000);
#[AsCommand(
    name: 'messenger:monitor:purge:worker',
    description: 'Remove all worker ids from the cache.',
)]
class MessengerMonitorPurgeWorkerCommand extends Command
{
    public function __construct(
        private readonly CacheInterface $cache
    )
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $item = $this->cache->getItem("zenstruck_messenger_monitor.worker_ids");
        $item->set([]);
        $this->cache->save($item);

        return Command::SUCCESS;
    }
}

So basically, it would be nice to have a command for that like mine or any other solution to automatically remove workers which aren't really running.
The command works in my case, but I am sure in other cases, without restarting the workers, they won't register themselves again.

@Chris53897
Copy link
Contributor

Could you please provide your symfony version and explain what 'docker compose stop xxx_worker' calls.
Does it dispatch WorkerStoppedEvent?

@chapterjason
Copy link
Author

chapterjason commented Jul 10, 2024

Hey @Chris53897, I might wasn't explicit enough. I especially talking about the scenario in which the WorkerStoppedEvent won't get called.

In my case the xxx_worker service container is just a simple php bin/console messenger:consume async -vv. But to be explicit, in my cases the event won't get called as the service will be killed a lot in development, which results in the lose cache objects.

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

No branches or pull requests

2 participants