islco / django-rq-scheduler

A database backed job scheduler for Django RQ and RQ Scheduler
MIT License
42 stars 46 forks source link

Repeatable job ignores selected queue and runs on default #36

Open striveforbest opened 5 years ago

striveforbest commented 5 years ago

I have a Repeatable job created via admin to run every 15 minutes on a scheduled queue. See screenshot1:

screenshot1

However, looking at the Queues in the admin, it's apparent that job is running on the default queue instead. See screenshot2:

screenshot2

Separately, the admin doesn't report successfully finished jobs (besides one repeated job). I can confirm many jobs are succeeding but not showing up in the admin. See screenshot3:

screenshot3
marianstefi20 commented 5 years ago

This will be a mouthful, but if you want to see the solution, skip this list and go to Solution.

Solution: run python manage.py rqscheduler --queue=<name> (of course this is not in the documentation of django-rq). Funky solution: (I'm almost joking here) fork rq_scheduler and change scheduler.py's get_queue_for_job(self, job) function...just a little: From this:

def get_queue_for_job(self, job):
        """
        Returns a queue to put job into.
        """
        if self._queue is not None:
            return self._queue
        key = '{0}{1}'.format(self.queue_class.redis_queue_namespace_prefix,
                              job.origin)
        return self.queue_class.from_queue_key(
                key, connection=self.connection, job_class=self.job_class)

To this:

def get_queue_for_job(self, job):
        """
        Returns a queue to put job into.
        """
        if job.origin is not None:
            return job.origin
        if self._queue is not None:
            return self._queue
        key = '{0}{1}'.format(self.queue_class.redis_queue_namespace_prefix,
                              job.origin)
        return self.queue_class.from_queue_key(
                key, connection=self.connection, job_class=self.job_class)
striveforbest commented 5 years ago

@marianstefi20 thanks for digging in.

I am running scheduler via systemd. I will try to update my systemd service to:

[Unit]
Description=Django-RQ Scheduler Service
After=network.target

[Service]
Environment=DJANGO_SETTINGS_MODULE=proj.settings
Environment=DJANGO_CONFIGURATION=Production
WorkingDirectory=/srv/www/proj/
ExecStart=/srv/www/fuweb/.venv/bin/python /srv/www/proj/manage.py rqscheduler --queue=scheduled

[Install]
WantedBy=multi-user.target

However, I think it should be considered as bug.

marianstefi20 commented 5 years ago

At a closer inspection, the master branch from rq-scheduler already solved this issue, by removing:

if self._queue is not None:
            return self._queue

from get_queue_for_job.

Try updating rq-scheduler to the latest version. If you look at https://github.com/rq/rq-scheduler/commits/master you will see they added yesterday something (Add queue_name to enqueue_in and enqueue_at), but most importantly, they made a new release 0.9.1. This might do it.

marianstefi20 commented 5 years ago

I've updated rq-scheduler and the problem with the queues has been fixed. I can confirm that the admin doesn't report the finished jobs correctly (I'm manually deleting the jobs, but they still show up).

striveforbest commented 5 years ago

@marianstefi20 thanks for the update. I will upgrade and re-test. Bummer it still doesn't report the finished jobs correctly.