wallet/apps/users/tasks.py
Sayyid Hamid Mahdavi 8cac19570f set time out
2020-11-22 16:08:48 +03:30

28 lines
930 B
Python

from celery import shared_task
from django.conf import settings
from service_clients import Client, AccountsClient
SCOPES = ['notifications.notification:submit']
client = Client(client_id=settings.CLIENT_ID,
client_secret=settings.CLIENT_SECRET,
scopes=SCOPES,
grant_type=AccountsClient.GRANT_CLIENT_CREDENTIALS)
@shared_task
def send_notification(phone_number=None,
title=None,
body=None,
user_uuid=None,
email=None,
notification_type=1):
data = {
'phone_number': phone_number,
"body": f'{title}:\n{body}'
}
try:
print(client.request(required_scopes=SCOPES, url=f'{settings.BASE_NOTIFICATION_URL}/notifications/', data=data,
method='post', timeout=5).text)
except Exception as e:
print(e)