[PYTHON] Even if you cancel or delete the job in the queue, the process running on the worker does not stop.

Premise

Register a job

from django_rq import get_queue

q = get_queue()
job = q.enqueue(processing)

Erase the job

from django_rq import get_queue

q = get_queue()

job_id = ***
job = q.fetch_job(job_id)

job.cancel()
job.delete()

β†’ The processing running on the worker has not stopped

Os.kill (pid) using the pid that the process is running

Check the pid in the process and give it to the job meta

def processing:
  job = get_current_job()
  worker = get_worker()
  job.meta['pid'] = worker.pid
  job.save()

  ...

Os.kill (pid) when killing a job

from django_rq import get_queue
import os
import signal

q = get_queue()

job_id = ***
job = q.fetch_job(job_id)

pid = job.meta['pid']
os.kill(int(pid), signal.SIGTERM)

job.cancel()
job.delete()

Summary

――Is there any other good way?

Postscript

Add a good method

reference

Recommended Posts

Even if you cancel or delete the job in the queue, the process running on the worker does not stop.
Even if you cancel or delete the job in the queue, the process running on the worker does not stop (2)
python> does not include the letters mm> if "mm" not in text: / print "not including mm"
[Learning memo] Create if the directory does not exist / Get the files in the directory