romanzipp / Laravel-Queue-Monitor

Monitoring Laravel Jobs with your Database
https://packagist.org/packages/romanzipp/laravel-queue-monitor
MIT License
693 stars 91 forks source link

Any thoughts on how this might be used to kill a running job? #70

Closed oobi closed 1 year ago

oobi commented 3 years ago

This is probably a feature request but I haven't found any good info on this in the Laravel docs.

Is there a way to hook the "delete" action on a running job to kill the task itself or interrupt it?

romanzipp commented 3 years ago

Laravel does not include include any functionality like this out of the box. I've already implemented a similar functionality by storing the process ID in the queue data.

public function handle(): void
{
    if (function_exists('posix_getpid')) {
        $this->queueData(['process_id' => posix_getpid()]);
    }
}

You could you posix_kill to kill the process.

I'll look into this further and setup a PR 👍