tasks.py 476 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from celery import shared_task
from django.apps import apps


@shared_task
def send_message(message_id):
    """Send a push notification"""

    print('Sending push notification {}'.format(message_id))

    ScheduledMessage = apps.get_model('pushnotifications', 'ScheduledMessage')
    try:
        message = ScheduledMessage.objects.get(pk=message_id)
    except ScheduledMessage.DoesNotExist:
        print('Cannot find ScheduledMessage')
        return

    message.send()