Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Queue classes, Worker Classes, Job Classes in Python rq package

While reading through the rq docs, I notice that there are some arguments that you can pass to rq worker when starting the worker

Example:

rq worker --worker-class 'foo.bar.MyWorker'

Argument list includes

  • --worker-class or -w: RQ Worker class to use (e.g rq worker --worker-class 'foo.bar.MyWorker')
  • --job-class or -j: RQ Job class to use.
  • --queue-class: RQ Queue class to use.

What are worker classes, job classes and queue classes, and when do you utilize them?

like image 601
Nyxynyx Avatar asked Jun 20 '18 19:06

Nyxynyx


People also ask

What is Python worker class?

A worker is a Python process that typically runs in the background and exists solely as a work horse to perform lengthy or blocking tasks that you don't want to perform inside web processes.

What is RQ Redis?

RQ, also known as Redis Queue, is a Python library that allows developers to enqueue jobs to be processed in the background with workers. The RQ workers will be called when it's time to execute the queue in the background.


1 Answers

It's just inheritance of classes ( Worker from rq for example )

Let it as base_worker.py

import pseudo_realy_necessery_library_for_every_job

from rq import Worker as BaseClass
class Worker(BaseClass):
    def __init__(self, queues=None, *args, **kwargs):
        u'''
        Constructor.

        Accepts the same arguments as the constructor of
        ``rq.worker.Worker``.
        '''


        super().__init__(queues, *args, **kwargs)

and u can run

rq worker --worker-class='base_worker.Worker'

In my case I have exclude reloading library for every new job

like image 188
user11354529 Avatar answered Oct 21 '22 12:10

user11354529