【发布时间】:2019-09-16 05:58:45
【问题描述】:
我正在使用 celery beat schedule 在午夜自动重置属性。之后,我还想使用 firebase 向所有相关用户发送通知。所以,我写了以下代码。
def send_notification(reg_ids, data_message):
push_service = FCMNotification(api_key=fcm_config['GCM_API_KEY'])
push_service.multiple_devices_data_message(registration_ids=reg_ids, data_message=message)
@shared_task
def reset_daily_count():
try:
User.objects.all().update(daily_attempts=3)
except Exception as e:
logger.debug(e)
else:
send_notification(reg_ids, data_message)
但是这段代码会创建FCMNotification 对象,每次我都会调用它。我想要的是创建一个对象并在需要时从某个地方访问它,即使对于其他芹菜任务,不仅是定期任务,还有正常任务。我该怎么做?
【问题讨论】:
标签: django django-rest-framework django-views celery