Reputation: 154484
Is it possible to ignore task results on a per-invocation basis?
For example, so I can ignore the results of tasks when they are being run during a web request, but wait for the result (which might have, eg, debug info) when I'm running the task interactively?
I know that Tasks have the ignore_result
flag, but I'm wondering specifically if it's possible to set ignore_result
on a per-invocation basis (not a "global" basis).
Upvotes: 3
Views: 1331
Reputation: 1
You can use ignore_result=True/False
while calling apply_async
or delay
@app.task
def hello():
print('hello world')
# storing/rejecting results per invocation basis
res = hello.apply_async(ignore_result=True)
res1 = hello.apply_async(ignore_result=False)
You might run into this error if you are running an older version of celery. You can read the docs about how to use ignore_result
in more detail here
Upvotes: 0
Reputation: 2961
Not normally, because ignore_result is a property of a Task that only the workers use (to decide whether to send a result back).
But you could do it if you used your own task parameter (avoid calling it ignore_result), and have the task set its ignore_result based on that:
task mytask(please_ignore_result):
mytask.ignore_result = please_ignore_result
Upvotes: 1