Created
October 23, 2021 02:29
-
-
Save lucaspolo/a23c62f7c1189eb84ab8be5482e3177c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## config.py | |
CELERY_BROKER_URL = 'redis://localhost/0' | |
CELERY_BEAT_SCHEDULE = { | |
'envia-emails-a-cada-30-segundas': { | |
'task': 'tasks.envia_email', | |
'schedule': 10.0, | |
} | |
} | |
## tasks.py | |
import time | |
from main import app | |
@app.task | |
def envia_email(): | |
lista_de_usuarios = [ | |
'Monica', | |
'Cebolinha', | |
'Magali', | |
'Cascão', | |
'Louco', | |
'Tina', | |
'Rolo', | |
] | |
for usuario in lista_de_usuarios: | |
print(f'Enviando email para {usuario}...') | |
time.sleep(1) | |
print(f'Email enviando para {usuario}!') | |
## main.py | |
from celery import Celery | |
app = Celery('tasks') | |
app.autodiscover_tasks(lambda: ['tasks']) | |
app.config_from_object('config', namespace='CELERY') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment