为什么导致django RQ成为:pickle数据被截断?

时间:2018-05-17 18:42:33

标签: python django redis scheduled-tasks

我无法弄清楚我的代码中有什么问题。我想将queryset推迟到django rq,请帮帮我这是我的代码:

views.py

class PartnerCatalogueView(generic.ListView):
"""
Browse all products in the catalogue based on vendor
"""
template_name = 'catalogue/vendorku.html'
# paginate_by = 9
model = Product
context_object_name = 'prod'

def get_queryset(self, **kwargs):
    queryset = super(PartnerCatalogueView, self).get_queryset()
    queue = django_rq.get_queue('high', autocommit=True, async=True, default_timeout=360)
    u = self.kwargs['pk']
    a = queue.enqueue(long_runnig_task, u)
    time.sleep(0.2)
    queryset = a.result
    return queryset

tasks.py

@job("high", timeout=360)
def long_runnig_task(s):
  o = Product.objects.filter(stockrecords__partner__id=s)
  return o

在工作终端,我得到了这个结果:

18:33:07 high: Job OK (c7f769d0-0d79-426e-8428-c6246ed736bf)
18:33:07 Result: '<ProductQuerySet [<Product: tes>, <Product: OKe>]>'
18:33:07 Result is kept for 500 seconds
18:33:07 Sent heartbeat to prevent worker timeout. Next one should 
arrive within 420 seconds.
18:33:07 Sent heartbeat to prevent worker timeout. Next one should 
arrive within 420 seconds.
18:33:07 *** Listening on high,low...
18:33:07 Sent heartbeat to prevent worker timeout. Next one should 
arrive within 420 seconds.

在django终端,我得到了这些结果:

File "/Users/ibadi/.virtualenvs/myshop/lib/python3.6/site-packages/django/views/generic/list.py", line 160, in get
self.object_list = self.get_queryset()
File "/Users/ibadi/oke/grosire/apps/catalogue/views.py", line 33, in get_queryset
queryset = a.result
File "/Users/ibadi/.virtualenvs/myshop/lib/python3.6/site-packages/rq/job.py", line 395, in result
self._result = loads(rv)
_pickle.UnpicklingError: pickle data was truncated

0 个答案:

没有答案