我已经编写了python文件来编写数据库中的东西。 此任务是在RabbitMQ队列中添加。 DB如何自动消耗任务来自队列?
import MySQLdb
from celery import Celery
import pika
app2 = Celery('task2', broker='amqp://guest@localhost//')
@app2.task(queue='Test')
def update_db():
# Open database connection
db = MySQLdb.connect("localhost","root","root","test" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
# Prepare SQL query to DELETE required records
sql = "insert into tt values(1,'james')"
#print sql
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
# disconnect from server
db.close()
答案 0 :(得分:0)