Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make the error handler for a backburner worker just kill the worker process

I have a fleet of Backburner workers (Backburner::Workers::Simple). I seem to have hit an edge case where a worker occasionally can't get a DB connection, the job is reaped back by the server, and suddenly the worker goes on a tear, reserving jobs rapid-fire, all of which time out and eventually get buried, because the worker never again successfully gets a DB connection. Obviously, it would be ideal if I could fix the weirdness around DB connections and rapid-fire job reservation. That seems like a longer-term solution, though, because I've looked and don't see anything obvious. What I'd like to do is just have my error handler log the error, and then for the whole worker process to die. All of my workers are under process supervision, so this is a very clean, simple way to get a fresh worker without the DB problem. I've tried adding ; Kernel.exit (and variations on that) to my on_error lambda, but it doesn't seem to make a difference. How do I make this happen?

like image 296
Hank Gay Avatar asked Aug 31 '18 13:08

Hank Gay


1 Answers

If the need is to kill the worker completely, no matter what, you can make a call to command line from ruby with system() to run a kill command.

So you just need to get the PID of the worker and then kill it from system call

system("kill -QUIT #{worker.pid}")

looking at how to get the PID of the worker, I get this information from backburner repository, and it seems like you can get the PID from the worker with

Process.pid
like image 189
xploshioOn Avatar answered Nov 10 '22 18:11

xploshioOn