Skip to content

Instantly share code, notes, and snippets.

View sikaili99's full-sized avatar
🎯
I am ready for it! 💻

Mathews Musukuma sikaili99

🎯
I am ready for it! 💻
View GitHub Profile
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_twilio.settings')
app = Celery('django_twilio')
from celery import task
from celery import shared_task
from sms_app.middleware import TwillioNotificationMiddleware
# We can have either registered task
@task(name='send-sms')
def send_sms_task(message,phone,dlivery_time,delivery_day):
TwillioNotificationMiddleware.process_sms(message,phone,dlivery_time,delivery_day)
from celery.schedules import crontab
CELERY_BROKER_URL = 'redis://localhost:6379' #You can also refrence a remote url from e.g heroku
CELERY_TIMEZONE = 'Europe/Warsaw'
HOUR = 0
DAY = 0
# Let's make things happen
CELERY_BEAT_SCHEDULE = {
'send-sms-every-hour': {
'task': 'send-sms',
@sikaili99
sikaili99 / middleware.py
Last active March 26, 2021 01:33
Sending sms that are scheduled in django using Twilio and Celery
import json
import logging
import os
from django.conf import settings
from django.views import GenericView
from django.core.exceptions import ImproperlyConfigured
from dotenv import load_dotenv
from twilio.rest import Client