Skip to content

Instantly share code, notes, and snippets.

@lukassup
Created March 28, 2021 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukassup/ae45da93f7df30257fde98b3790d7e83 to your computer and use it in GitHub Desktop.
Save lukassup/ae45da93f7df30257fde98b3790d7e83 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from time import sleep
from tasks import add
result = add.delay(4,4)
sleep(0.1) # wait 0.1s
result.ready()
print(result.get())
#!/usr/bin/env python3
from celery import Celery
app = Celery('tasks', backend='redis://localhost', broker='redis://localhost')
@app.task
def add(x, y):
return x + y
@lukassup
Copy link
Author

lukassup commented Mar 28, 2021

Install deps:

brew install redis python pipenv

Run redis:

redis-server /opt/homebrew/etc/redis.conf

Install Celery:

pipenv install 'celery[redis]'

Run Celery worker:

pipenv run celery -A tasks worker --loglevel=INFO

Execute task:

pipenv run ./run_task.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment