Skip to main content

Celery taskcls decorator

Project description

Celery Decorator taskcls

  • Free software: MIT License

Logo

This package is temporary way to get app.taskcls decorator right now. The main target of this package make you able to use taskcls decorator before celery 4.5 released, and then you can remove this package import without application code change

More about: https://github.com/celery/celery/pull/5755

Features

import celery_decorator_taskcls
celery_decorator_taskcls.patch_celery()

from celery import Celery
app = Celery(...)

class BaseTask:
    def __init__(self, task, **kwargs):
        self.task = task
        for key, value in kwargs.items():
            setattr(self, key, value)

    @classmethod
    def task(cls, task, **kwargs):
        instance = cls(task, **kwargs)
        return instance.main()


@app.taskcls(bind=True)
class SimpleTask(BaseTask):
    def main(self):
        ...

app.taskcls decorator behavior is the same as app.task. You can pass it kwargs like bind, name or other or you can use it without kwargs

You can also pass default decorator options by nested class MetaTask:

class BaseTask:
    class MetaTask:
        bind = True

    @classmethod
    def task(cls, taks, *args, **kwargs):
        ...

Patching options

By default patcher search Celery.taskcls attribute. If it not found, patcher creates it. But when it exists (I belive you find it in Celery 4.5), patcher checks its optional argument force, because it seems patching not required. Calling celery_decorator_taskcls.patch_celery(force=True) enforces patching Celery even Celery.taskcls exists

Changelog

[0.1.4]

  • Allow to inherit taskcls from another taskcls
  • Comment code blocks to simplify its understanding

[0.1.3]

  • Fix MetaTask inheritance

[0.1.2]

  • Update Readme

[0.1.1]

  • Add chandelog
  • Rename nested class Meta to MetaTask

[0.1.0]

  • Initial commit

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

celery-decorator-taskcls-0.1.4.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

celery_decorator_taskcls-0.1.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file celery-decorator-taskcls-0.1.4.tar.gz.

File metadata

  • Download URL: celery-decorator-taskcls-0.1.4.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for celery-decorator-taskcls-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1dd1ad58f03ff2575bf09365d2765215b77d2cd6ddaa91e920b19fdba08ba630
MD5 f8fe74df094fa1d9156c4e3cd72198db
BLAKE2b-256 eb8b5899fdad26627221211036e4c34e23f13beeb5fcfad0567810eaf5290aad

See more details on using hashes here.

File details

Details for the file celery_decorator_taskcls-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: celery_decorator_taskcls-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for celery_decorator_taskcls-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d7e3be4d1b57bad901b31ed55ed2f875d5e0ce01ed7c8b8c5c751e77486eb47e
MD5 81a68afeb99b17a8c442f1334f343227
BLAKE2b-256 be757b6cf78f88b3b65f601f8e5058e8ffa83541ec923e2a107b39c7ff806a07

See more details on using hashes here.

Supported by

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