Skip to main content

No project description provided

Project description

tgext.rq

tgext.rq is a TurboGears2 extension that simplify rq usage for async jobs.

TLDR

Install

pip install tgext.rq #or

#setup.py
install_requires = [
    "TurboGears2 >= 2.4.3",
    "rq",
    ...,
    "tgext.rq"

Plug into TurboGears:

#config/app_cfg.py

import tgext.rq
tgext.rq.plugme(base_config)

Add configs:

#development.ini

redis.url = redis://127.0.0.1:6379/0
tgext.rq.application_queues_module = app.workers.queue
tgext.rq.application_queues_function = application_queues

Provide a method so tgext.rq know all queues that your application uses:

#app.workers.queue.py

def application_queues():
  return ['high_priority', 'default_priority', 'low_priority']

Run worker:

gearbox rq

Installing

Add tgext.rq to your setup.py, inside install_requires, something like:

#setup.py

install_requires = [
    "TurboGears2 >= 2.4.3",
    "rq",
    ...,
    "tgext.rq"

or install via pypi:

pip install tgext.rq

Enabling

To enable tgext.rq put inside your application config/app_cfg.py the following:

#config/app_cfg.py

import tgext.rq
tgext.rq.plugme(base_config)

Configuration

All configurations listed here should be done on tg .ini files, like development.ini or production.ini

Redis URL

#development.ini

redis.url = redis://USERNAME:PASSWORD@IP.ADDRESS.0.1:6379/DATABASE_NUMBER
redis.url = redis://user:test@127.0.0.1:6379/0
redis.url = redis://127.0.0.1:6379/0
redis.url = redis://redis/0 #If you use docker-compose to up redis

This config is required.

Queues

tgext.rq needs to know what queues it should listen and your application have to supply a module and function to do that. For example:

Imagine that your application have the following module: app.workers.queue.py:

#app.workers.queue.py

def application_queues():
  return ['high_priority', 'default_priority', 'low_priority']

You need to set these configs:

#development.ini

tgext.rq.application_queues_module = app.workers.queue
tgext.rq.application_queues_function = application_queues

ps: For now, only modules are supported. No classes.

This config is required.

Optional configs

#development.ini

tgext.rq.default_job_timeout = 180 #default value is 180.

Run RQ

tgext.rq provides a tg command to run a rq worker:

gearbox rq -c production.ini

or using the default development.ini file:

gearbox rq

Multithreding with Gevent

tgext.rq comes with options to use a gevent worker to enable more concurrency on job execution, to enable first add gevent to install_requires on setup.py

#setup.py

install_requires = [
    "TurboGears2 >= 2.4.3",
    "rq",
    ...,
    "tgext.rq >= 0.0.7",
    "gevent >= v1.1.2"

Then configure tgext.rq to use GeventWorker class:

#development.ini

tgext.rq.worker_class = GeventWorker #default value is: Worker
tgext.rq.gevent_pool_size = 3 #default value is: 20

If you receive any errors related to gevent patches, like:

super(SSLContext, SSLContext).options.__set__(self, value) [Previous line repeated 473 more times] RecursionError: maximum recursion depth exceeded

You need to patch manually your application before it loads, add these lines before everything else on app_cfg.py

from gevent import monkey
monkey.patch_all()

Contributions

Future Needs:

  • tests
  • more rq config options
  • [add your needs here]

PRs are welcome!

Thanks

How to upload to Pip

This section is for the maintainer to remember how to upload to pypi. Move along.

python setup.py sdist
pip install twine
twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tgext.rq-0.0.7.tar.gz (7.9 kB view details)

Uploaded Source

File details

Details for the file tgext.rq-0.0.7.tar.gz.

File metadata

  • Download URL: tgext.rq-0.0.7.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.4

File hashes

Hashes for tgext.rq-0.0.7.tar.gz
Algorithm Hash digest
SHA256 7cd6bffacc2659d4fbe1d3d54a1700b8f2963e680b82415b2cb1dbcfc969108e
MD5 27ca3b95592adcd4e2755980c7cf7951
BLAKE2b-256 fb407b7adc6eb39100ab04045be51d78e68de32e19816130b50e834884150379

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page