【问题标题】:too large list parameter to celery芹菜的列表参数太大
【发布时间】: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


    【解决方案1】:

    将大值存储在 Redis 中,并传递对它的引用通常是最好的方法。 您不能将生成器传递给 celery 任务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多