【发布时间】:2016-01-06 05:37:27
【问题描述】:
我正在使用以下代码发送 gcm 通知。
registration_ids 很大,因为它是接收者的数量。
有没有办法以某种方式减少该参数?
@shared_task
def gcm_send_json(registration_ids, data, index=0, **kwargs):
NUM_REGISTRATION_ID = SETTINGS.get("GCM_MAX_RECIPIENTS")
range_limit = index + NUM_REGISTRATION_ID
sub_registration_ids = registration_ids[index: range_limit]
if not sub_registration_ids:
return
_gcm_send_json(sub_registration_ids, data, **kwargs)
if not kwargs:
kwargs = {}
kwargs.update({
'index': range_limit
})
eta = timezone.now() + datetime.timedelta(minutes=5)
gcm_send_json.apply_async(args=[registration_ids, data], kwargs=kwargs, eta=eta)
我可能可以将registration_ids存储在redis中,并从gcm_send_json访问它,并在我迭代整个列表时将其删除。
(不确定这是最好的解决方案..)
或者我可以使用生成器吗?
【问题讨论】:
标签: python django google-cloud-messaging celery