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

Terminate Worker/Queue #25

Closed
cj opened this issue Oct 22, 2011 · 6 comments
Closed

Terminate Worker/Queue #25

cj opened this issue Oct 22, 2011 · 6 comments

Comments

@cj
Copy link

cj commented Oct 22, 2011

Hi,

Is it possible to grab a queue/worker by name and stop (kill) it?

Many thanks,

CJ

@cj
Copy link
Author

cj commented Oct 22, 2011

I tried this but with no luck... the work is still running:

    $worker= Resque_Worker::find('Air.local:19948:ccc');
    print_r($worker);
    $worker->shutdown();
    print_r($worker);

@cj
Copy link
Author

cj commented Oct 22, 2011

The worker has shutdown to 1... so shouldn't it kill the process?


Resque_Worker Object
(
    [logLevel] => 0
    [queues:Resque_Worker:private] => Array
        (
            [0] => ccc
        )

    [hostname:Resque_Worker:private] => Air.local
    [shutdown:Resque_Worker:private] => 1
    [paused:Resque_Worker:private] => 
    [id:Resque_Worker:private] => Air.local:19948:ccc
    [currentJob:Resque_Worker:private] => 
    [child:Resque_Worker:private] => 
)

@cj
Copy link
Author

cj commented Nov 1, 2011

Looks like inside the loop $this doesn't get update at all.....

@cj
Copy link
Author

cj commented Nov 1, 2011

So in the Resque_Worker I changed the shutdown function to:

    /**
     * Schedule a worker for shutdown. Will finish processing the current job
     * and when the timeout interval is reached, the worker will shut down.
     */
    public function shutdown()
    {
        foreach($this->workerPids() AS $pid)
        {
            $this->shutdown = true;
            posix_kill($pid, SIGQUIT);
            $this->log('Exiting...');
        }
    }

Now things work as expected. I'll update the other functions too and send a pull request.

@chrisboulton
Copy link
Owner

Hi,

Sorry, I haven't had much time recently to have a look over this.

I think the problem with a proposed fix like this is that it's likely to kill all of the workers on the same box. If you spawn multiple workers, $worker->workerPids() is likely to go ahead and return ALL those that exist on the server.

In fact, I'm curious as to why you're having problems with the current method. Are you trying to stop workers outside of the context of php-resque?

If so, you should be able to send them the SIGQUIT from anything else, and they should shutdown after the current job has been processed.

@cj
Copy link
Author

cj commented Nov 2, 2011

No problem.... Yee that's what it ended up doing... SIGQUIT works just fine :) I do have one other question about finding the correct pid, there doesn't seem to find a worker(s) by their queue name. You either have to find all or find by the exact name... is there a reason for this?

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