Я не могу понять, что не так в моем коде. Я хочу отложить набор запросов до 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