DEV Community

Uhtred M.
Uhtred M.

Posted on • Edited on

3 1

Django Cloud Task Queue

I’m developing and maintaining a Python package to easily integrate your Django Application with Google Cloud Task.

Some features:

  • Easily push tasks to Cloud Task using a decorator
  • Automatically route all tasks from a single endpoint
  • Ease scheduling with native python datetime
  • Named task to avoid duplicated
  • Local development support with Redis Queue

Simple and beautiful task definition

from datetime import timedelta
from django.utils.timezone import now
from cloudtask import (
    CloudTaskRequest,
    task)

@task(queue='default')
def add(request: CloudTaskRequest, a: int = 5, b: int = 4) -> None:
    print(f'Running task with args {a=} and {b=}')
    print(a + b)

# pushing task to queue
add(a=2, b=4).delay()

# executing the task immediately without push to queue
add(a=30)()

# scheduling the task
at = now() + timedelta(days=1)
add(b=15).schedule(at=at)
Enter fullscreen mode Exit fullscreen mode

See the repository and full documentation on my Github page.

Thanks to the project bazaar.


If it was helpful or if you found it interesting, also leave an 🙋🏽‍♂️❤️ in the comments. Thank you, looking forward to the next article. Enjoy and follow my work.

Thanks,
Stay safe!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay