我使用eta来编程任务:
test.apply_async(eta=datetime(2019, 8, 4, 17, 01))
,但是我在test.py上有一个从视图中进行arg的任务,例如"帖子":
app = Celery()
@app.task(bind=True)
def test(post, self):
#somecode
我需要通过'eta'和'post',我尝试:
test.apply_async(post, eta=datetime(2019, 8, 4, 17, 01))
但给出一个错误:
functools.partial object argument after * must be an iterable, not Author
怎么了?
edit1
尝试:
test.apply_async(args=(post.id,) eta=datetime(2019, 8, 4, 17, 01))
它尝试运行任务:
@app.task(bind=True)
def test(post, self):
takeit = Author.objects.get(pk=post)
print takeit
结果:
Traceback (most recent call last):
File "c:python27libsite-packagesceleryapptrace.py", line 382, in trace_task
R = retval = fun(*args, **kwargs)
File "c:python27libsite-packagesceleryapptrace.py", line 641, in __protected_call__
return self.run(*args, **kwargs)
File "pathto/test.py", line 122, in test
takeit = Author.objects.get(pk=post)
File "c:python27libsite-packagesdjangodbmodelsmanager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "c:python27libsite-packagesdjangodbmodelsquery.py", line 371, in get
clone = self.filter(*args, **kwargs)
File "c:python27libsite-packagesdjangodbmodelsquery.py", line 784, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "c:python27libsite-packagesdjangodbmodelsquery.py", line 802, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "c:python27libsite-packagesdjangodbmodelssqlquery.py", line 1250, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "c:python27libsite-packagesdjangodbmodelssqlquery.py", line 1276, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "c:python27libsite-packagesdjangodbmodelssqlquery.py", line 1210, in build_filter
condition = self.build_lookup(lookups, col, value)
File "c:python27libsite-packagesdjangodbmodelssqlquery.py", line 1104, in build_lookup
return final_lookup(lhs, rhs)
File "c:python27libsite-packagesdjangodbmodelslookups.py", line 24, in __init__
self.rhs = self.get_prep_lookup()
File "c:python27libsite-packagesdjangodbmodelslookups.py", line 74, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)
File "c:python27libsite-packagesdjangodbmodelsfields__init__.py", line 966, in get_prep_value
return int(value)
TypeError: int() argument must be a string or a number, not 'test'
您制作了一个常见的Python错别字...
您有def test(post, self):
真正应该是def test(self, post):
。通常在进行一些代码重构时发生...