简体   繁体   English

清单参数太大,无法显示芹菜

[英]too large list parameter to celery

I'm sending gcm notification using the following code. 我正在使用以下代码发送gcm通知。

The registration_ids is huge because it is # of recepients. registration_ids很大,因为它是#个收件人。

Is there a way to cut that parameter down somehow? 有没有办法以某种方式减少该参数?

 @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)

I can probably store the registration_ids in redis, and access it from gcm_send_json and delete it when I iterate the whole list. 我可能可以将registration_ids存储在redis中,并从gcm_send_json访问它,并在迭代整个列表时将其删除。 (not sure it's best solution..) (不确定这是最佳解决方案。)

or Could I use a generator? 或我可以使用发电机吗?

Storing the large value in Redis, and passing a reference to it is generally the best way to go. 通常,最好的方法是在Redis中存储较大的价值并传递对其的引用。 You can't pass a generator to the celery task. 您不能将生成器传递给芹菜任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM