i’m at Django part 3 , Running Background Tasks , Lesson 7 and 8 . I don’t see no output of from notify_customer function
In terminal I get this:
[2024-08-06 12:19:37,800: INFO/SpawnPoolWorker-430] child process 424 calling self.run()
[2024-08-06 12:19:37,807: INFO/SpawnPoolWorker-432] child process 19008 calling self.run()
[2024-08-06 12:19:37,825: INFO/SpawnPoolWorker-435] child process 17820 calling self.run()
[2024-08-06 12:19:37,826: INFO/SpawnPoolWorker-431] child process 4920 calling self.run()
[2024-08-06 12:19:37,832: INFO/SpawnPoolWorker-434] child process 264 calling self.run()
[2024-08-06 12:19:37,835: INFO/SpawnPoolWorker-429] child process 15808 calling self.run()
[2024-08-06 12:19:37,849: INFO/SpawnPoolWorker-433] child process 22064 calling self.run()
**[2024-08-06 12:19:41,582: INFO/MainProcess] Task playground.tasks.notifiy_customer[d8508a68-6326-4224-8b18-b319cc568069] received**
[2024-08-06 12:19:42,715: INFO/SpawnPoolWorker-438] child process 22144 calling self.run()
[2024-08-06 12:19:42,718: INFO/SpawnPoolWorker-436] child process 12332 calling self.run()
[2024-08-06 12:19:42,720: INFO/SpawnPoolWorker-442] child process 6196 calling self.run()
[2024-08-06 12:19:42,720: INFO/SpawnPoolWorker-440] child process 21416 calling self.run()
[2024-08-06 12:19:42,737: INFO/SpawnPoolWorker-439] child process 20920 calling self.run()
[2024-08-06 12:19:42,743: INFO/SpawnPoolWorker-441] child process 8848 calling self.run()
[2024-08-06 12:19:42,743: INFO/SpawnPoolWorker-437] child process 6996 calling self.run()
[2024-08-06 12:19:46,614: INFO/MainProcess] **Task playground.tasks.notifiy_customer[3bec96a1-4ee0-44dd-aa8d-03ec128f5005] received**
Here the code :
# settings.py:
CELERY_BROKER_URL = 'redis://localhost:6379/1'
CELERY_BEAT_SCHEDULE = {
'notifiy_customers':{
'task': 'playground.tasks.notifiy_customer',
'schedule':5,
'args': ['Welcome to my Backend project']
}
}
#celery.py
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'storefront.settings')
celery = Celery('storefront')
celery.config_from_object('django.conf:settings', namespace='CELERY')
celery.autodiscover_tasks()
# tasks.py:
from time import sleep
from celery import shared_task
# defining a task
@shared_task
def notifiy_customer(message):
print("Sending 10k emails")
print(message)
sleep(10)
print("Print Emails were successfully sent")
# views.py
from django.shortcuts import render
from .tasks import notifiy_customer
def say_hello(request):
notifiy_customer.delay('Welcome to my Backend project')
return render(request, 'hello.html', {'name': 'Mosh'})