Ich möchte den Status meiner Sellerie-Aufgabe von einer anderen Funktion aktualisieren. Hier ist, was ich habe jetzt:Flask Sellerie update_state von innerhalb einer anderen Funktion
der Route
@app.route('/my-long-function', methods=['POST'])
def my_long_function():
param1 = request.form['param1']
param2 = request.form['param2']
task = outside_function.delay(param1, param2)
return task.id
Sellerie Aufgabe - beginnt some_python_script.handle im Hintergrund
@celery.task(name='outside_function')
def outside_function(param1, param2):
with app.app_context():
some_python_script.handle(param1, param2)
some_python_script.handle:
def handle(param1, param2):
param1 + param2
# many, many different things
Idealerweise I Ich würde gerne in der Lage sein, die Sellerieaufgabe selbst zu aktualisieren. So kann ich den Status einfach von meiner App aus abfragen , Etwa so:
some_python_script.handle (idealerweise):
def handle(param1, param2):
param1 + param2
# many, many different things
self.outside_function.update_state('PROGRESS', meta = {'status':'progressing'})
Check Fortschritt (im Idealfall):
@app.route('/status/<task_id>')
def taskstatus(task_id):
task = outside_function.AsyncResult(task_id)
response = {
'state': task.state,
'id': task.id,
'status' : task.status,
}
return jsonify(response)
oder etwas ähnliches. Würde mich über jede Hilfe freuen, ich bin neu zu Sellerie!