2021-02-07 03:29:24 +01:00
|
|
|
# standard imports
|
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
|
|
|
# third-party imports
|
2022-01-04 17:51:02 +01:00
|
|
|
import cic_notify.tasks.sms.db
|
2021-04-07 08:31:26 +02:00
|
|
|
from celery.app.control import Inspect
|
2021-02-07 03:29:24 +01:00
|
|
|
import celery
|
|
|
|
|
|
|
|
# local imports
|
|
|
|
from cic_notify.tasks import sms
|
|
|
|
|
|
|
|
app = celery.current_app
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
2021-04-07 08:31:26 +02:00
|
|
|
|
2021-02-07 03:29:24 +01:00
|
|
|
class Api:
|
2022-01-04 17:51:02 +01:00
|
|
|
def __init__(self, queue: any = 'cic-notify'):
|
2021-02-07 03:29:24 +01:00
|
|
|
"""
|
|
|
|
:param queue: The queue on which to execute notification tasks
|
|
|
|
:type queue: str
|
|
|
|
"""
|
2021-06-14 09:38:23 +02:00
|
|
|
self.queue = queue
|
2021-02-07 03:29:24 +01:00
|
|
|
|
2022-01-04 17:51:02 +01:00
|
|
|
def sms(self, message: str, recipient: str):
|
2021-02-07 03:29:24 +01:00
|
|
|
"""This function chains all sms tasks in order to send a message, log and persist said data to disk
|
|
|
|
:param message: The message to be sent to the recipient.
|
|
|
|
:type message: str
|
|
|
|
:param recipient: The phone number of the recipient.
|
|
|
|
:type recipient: str
|
|
|
|
:return: a celery Task
|
|
|
|
:rtype: Celery.Task
|
|
|
|
"""
|
2022-01-04 17:51:02 +01:00
|
|
|
s_send = celery.signature('cic_notify.tasks.sms.africastalking.send', [message, recipient], queue=self.queue)
|
|
|
|
s_log = celery.signature('cic_notify.tasks.sms.log.log', [message, recipient], queue=self.queue)
|
|
|
|
s_persist_notification = celery.signature(
|
|
|
|
'cic_notify.tasks.sms.db.persist_notification', [message, recipient], queue=self.queue)
|
|
|
|
signatures = [s_send, s_log, s_persist_notification]
|
|
|
|
return celery.group(signatures)()
|