Skip to main content

Write Celery task as a class

Project description

Added as_task() method:

from celery import Celery
from celery import shared_task

from celery_task_class import Task

app = Celery(
    broker="redis://localhost:6379/0",
    backend="redis://localhost:6379/0",
)


class MyTask(Task):
    def run(self, *args, **kwargs):
        print('MyTask.run()')


@shared_task(base=MyTask, bind=True)
def run(self, *args, **kwargs):
    print('run() function task')
    super(self.__class__, self).run(*args, **kwargs)


class MyTask2(MyTask):
    def run(self, *args, **kwargs):
        print('MyTask2.run()')
        super().run(*args, **kwargs)


my_task = MyTask.as_task()
my_task2 = MyTask2.as_task()

Caller:

from mycode import my_task

my_task.delay()

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_task_class-0.1.0.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celery_task_class-0.1.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file celery_task_class-0.1.0.tar.gz.

File metadata

  • Download URL: celery_task_class-0.1.0.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.14 Darwin/24.6.0

File hashes

Hashes for celery_task_class-0.1.0.tar.gz
Algorithm Hash digest
SHA256 32d77fdd8fd1c99cde28f1188411b8a226e54b5a0ab98f855da9133bb519d0c7
MD5 1e64b172476d6e7827caef4b97176dfb
BLAKE2b-256 13b5ad9fc0e1efbe82edfeee04cebcb5a629342fa5b1b96120661655f88308d5

See more details on using hashes here.

File details

Details for the file celery_task_class-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: celery_task_class-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.14 Darwin/24.6.0

File hashes

Hashes for celery_task_class-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a4c1e88e3ae3f3603cca3cf7c5b2d671141e679594524561a6308cd245437c2
MD5 d512b71c95a28ee2e05f3cf8e46b389c
BLAKE2b-256 63657510997a6183ff7eab322637cf4457f28e0b4f5ffedec1d45af79cf83626

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