我有一个小保温瓶+餐具应用程序,我正在用花来监视任务,完成后我需要根据输出更改任务的状态,但我不能这样做,代码是:
import requests
from flask import Flask, escape, request, jsonify
from flask.logging import default_handler
import logging
import os
from dotenv import load_dotenv
load_dotenv()
from pathlib import Path # python3 only
from logging.config import dictConfig
from celery import Celery, current_task
from tasks import make_celery
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
logging.basicConfig(filename='app.log', filemode='a', datefmt='%d-%b-%y %H:%M:%S' , format='%(asctime)s %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Flask code
flask_app = Flask(__name__)
flask_app.debug = True
flask_app.config.update(
CELERY_BROKER_URL='pyamqp://amr:admin@rabbitmq-celery:5672/celery',
CELERY_RESULT_BACKEND='redis://redis-celery/0'
)
celery = make_celery(flask_app)
@celery.task(bind=True)
def name(self,me):
if me == "amr6":
self.update_state(state='FFAAII')
msg = f'Helloo {me}'
else:
msg = "OK"
return msg
@flask_app.route('/api/<n>', methods=['POST'])
def hello(n):
result = name.delay(n)
return result.wait()
那只是代码的一部分