python - passing django request object to celery task -
i have task in tasks.py so:
@app.task def location(request): ....
i trying pass request object directly few task so:
def tag_location(request): tasks.location.delay(request) return jsonresponse({'response': 1})
i getting error can't serialized guess? how fix this? trouble have file upload objects .. not simple data types.
because request object contains references things aren't practical serialize — uploaded files, or socket associated request — there's no general purpose way serialize it.
instead, should pull out , pass portions of need. example, like:
import tempfile @app.task def location(user_id, uploaded_file_path): # … stuff … def tag_location(request): tempfile.namedtemporaryfile(delete=false) f: chunk in request.files["some_file"].chunks(): f.write(chunk) tasks.location.delay(request.user.id, f.name) return jsonresponse({'response': 1})
Comments
Post a Comment