Skip to content

Instantly share code, notes, and snippets.

@nvie
Last active April 27, 2018 12:53
Show Gist options
  • Save nvie/4707624 to your computer and use it in GitHub Desktop.
Save nvie/4707624 to your computer and use it in GitHub Desktop.
Which API is the nicest for the new RQ with concurrency?
# Alt 1: very explicit, but requires knowledge on what type of workers exist
from rq.workers.gevent import GeventWorker
w = GeventWorker(4)
# Alt 2: A bit like an "Abstract Factory", no need for knowing the implementing
# class names, backward compatible, and kind='forking' by default
from rq import Worker
w = Worker(4, kind='gevent')
# Alt 3: I don't think (2) works without really nasty tricks. This one is as
# simple as (2), but uses a convenient class method, so we can return an instance
# of the implementing subclass instead. Switching worker impls is as easy as
# changing a single string.
from rq import Worker
w = Worker.create('gevent', 4)
# Alt 4: A helper function that wraps (1)
from rq import make_worker
w = make_worker('gevent', 4) # will return a rq.workers.gevent.GeventWorker
# with max 4 processes
@MrJohnsson77
Copy link

I'm all curious what the final decision was on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment