You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your usage notes for the view depends on the task returning a task_id:
def progress_view(request):
result = my_task.delay(10)
return render(request, 'display_progress.html', context={'task_id': result.task_id})
but a transaction.on_commit does not return a task_id, since the task may not have started yet. Any suggestions on how to use your progress bar with transactions?
Thanks!
Mark
The text was updated successfully, but these errors were encountered:
I didn't run this code. But it gives you the general idea.
# pre-generate a random idcustom_id=celery.utils.gen_unique_id()
# set task id to custom idtask_function=lambda: my_task.apply_async(args, task_id=custom_id)
# instead of passing my_task.apply_async directly, it's wrapped in a lambda function so we can give it argumentstransaction.on_commit(task_function)
Giving a task a custom task_id is a new concept for me. While we were talking, I implemented my progress bar using my Django site's MySQL db and uuid.uuid4().hex to generate a unique ID outside of the celery task, but I will take a look at using this approach when I have some free time. Yours will certainly be more efficient than periodically hitting the db to get the progress amount in my view. But, it does work!
Your usage notes for the view depends on the task returning a task_id:
but a transaction.on_commit does not return a task_id, since the task may not have started yet. Any suggestions on how to use your progress bar with transactions?
Thanks!
Mark
The text was updated successfully, but these errors were encountered: