Skip to main content

heavy_celery

https://badge.fury.io/py/heavy_celery.svg https://travis-ci.org/s1s5/heavy_celery.svg?branch=master https://codecov.io/gh/s1s5/heavy_celery/branch/master/graph/badge.svg

managed celery task

Documentation

The full documentation is at https://heavy_celery.readthedocs.io.

Quickstart

Install heavy_celery:

pip install heavy_celery

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'heavy_celery',
    ...
)

Features

settings.py

CELERY_DEFAULT_QUEUE = 'default'
CELERY_DEFAULT_EXCHANGE_TYPE = 'default'
CELERY_DEFAULT_ROUTING_KEY = 'default'

CELERY_QUEUES = (
    Queue('default', Exchange('default'), routing_key='default'),
    Queue('time_sensitive', Exchange('time_sensitive'), routing_key='time_sensitive_tasks'),
    Queue('background', Exchange('background'), routing_key='background'),
)

CELERY_REVOKE = 'example.apps.sample.tasks.celery_revoke'  # 適当なモジュールパスに変更
MIDDLEWARE += [
    'heavy_celery.middlewares.GlobalRequestMiddleware',
]

example/apps/sample/tasks.py

@app.task()
def celery_revoke(task_id):
    from celery.task.control import revoke
    revoke(task_id, terminate=True)

cronの機能を使うために

from celery.schedules import crontab
from <project_name>.celery_conf import app
from heavy_celery.cron import spawner as _cron_scheduler

@app.task()
def cron_scheduler():
    _cron_scheduler()

app.conf.beat_schedule = {
    'cron_scheduler': {
        'task': '<appname>.tasks.cron_scheduler',
        'schedule': crontab(),
        'args': (),
        'options': dict(queue='time_sensitive', routing_key='time_sensitive_tasks'),
    },
}

task定義の仕方

from heavy_celery import base

@app.task(base=base.Task)
def command(command_name, *args, **kw):
    call_command(command_name, *args, **kw)

タスクの定期実行のやり方

  • TaskSignatureの追加

  • name : タスク名

  • description : タスク詳細

  • task_path : タスクパス e.g) apps.foo.tasks.example_task

  • args : タスクに渡す引数(yaml形式)

  • kwargs : タスクに渡すkw引数(yaml形式)

  • options : タスクのスケジュールオプション、どのQueueにいれるかとか したみたいにしておけば、time_sensitiveのQueueで走るようになる

  • queue: time_sensitive routing_key: time_sensitive_tasks

  • CronScheduleの追加

  • name : cronタスク名

  • description : cronタスク詳細

  • cron_expr : cron表記

  • task : TaskSignatureオブジェクト

  • max_run_count : 最大繰り返し回数

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

Development

$ cookiecutter https://github.com/pydanny/cookiecutter-djangopackage

$ mkvirtualenv –no-site-packages heavy_celery $ pip install tox twine

# test $ make test-all

# release $ python setup.py publish # at first $ pip install readme_renderer # at first $ python setup.py check -r -s # syntax check $ make release

History

0.1.0 (2017-07-06)

  • First release on PyPI.

Metadata

Release files for heavy_celery 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for heavy_celery 0.3.0
File Size Uploaded Provenance Actions
heavy_celery-0.3.0.tar.gz 14.4 kB Without provenance Details for heavy_celery-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for heavy_celery 0.3.0
File Interpreter ABI Platform Actions
heavy_celery-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for heavy_celery-0.3.0-py2.py3-none-any.whl

Total release size: 31.3 kB

Release files / heavy_celery-0.3.0.tar.gz

Download URL heavy_celery-0.3.0.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
674c16953199eaf5bee5b95b1fd7be2971ebbe4a302ce9bd62f387ea57efebda
BLAKE2b-256 checksum
How to use checksums
7ca8ebda406716d0f902063cd03d3edf2ce142edf9fee59c20fd6d64ab44699e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Release files / heavy_celery-0.3.0-py2.py3-none-any.whl

Download URL heavy_celery-0.3.0-py2.py3-none-any.whl
Size 16.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
57c1f7e55bdf86993843a7a0dc105978dfd2c529bcddd97778ae5797a1d4c45b
BLAKE2b-256 checksum
How to use checksums
c16b4d6f881bace7b631d6322e1c974721e5084fe0e78d7b51f74f7e8d97954d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for heavy_celery 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page