Comments (5)
看一下代码
from rearq.
# main.py
from rearq import ReArq
from tortoise import Tortoise, connections
rearq = ReArq(db_url='mysql://root:[email protected]:3306/rearq')
db_config = {
"connections": {
"data": {
"engine": "tortoise.backends.mysql",
"credentials": {
"database": "data",
"host": "127.0.0.1",
"password": "123456",
"port": 3306,
"user": "root",
},
},
"big_data": {
"engine": "tortoise.backends.mysql",
"credentials": {
"database": "big_data",
"host": "127.0.0.1",
"password": "123456",
"port": 3306,
"user": "root",
},
},
"default": {
"engine": "tortoise.backends.mysql",
"credentials": {
"database": "rearq",
"host": "127.0.0.1",
"password": "123456",
"port": 3306,
"user": "root",
},
},
},
"apps": {
"data": {"models": [], "default_connection": "data"},
"big_data": {"models": [], "default_connection": "big_data"},
"rearq": {"models": ["rearq.server.models"], "default_connection": "default"},
},
"timezone": 'Asia/Shanghai'
}
@rearq.on_shutdown
async def on_shutdown():
# you can do some clean work here like close db and so on...
connections.close_all()
print("shutdown")
@rearq.on_startup
async def on_startup():
# you should do some initialization work here
await Tortoise.init(config=db_config)
print("startup")
@rearq.task(queue="q1")
async def add(self, a, b):
return a + b
#app.py
import uvicorn
from fastapi import FastAPI
from main import rearq
from rearq.server.app import app as rearq_app
app = FastAPI()
app.mount("/rearq", rearq_app)
rearq_app.set_rearq(rearq)
if __name__ == '__main__':
uvicorn.run(app="app:app", host="0.0.0.0", port=8999)
"""
exception:
File "/Users/zhouyuxin/Library/Caches/pypoetry/virtualenvs/rearq-test-5bSWUw0w-py3.10/lib/python3.10/site-packages/rearq/server/routes/index.py", line 26, in index
run_times = await JobResult.all().count()
File "/Users/aaa/Library/Caches/pypoetry/virtualenvs/rearq-test-5bSWUw0w-py3.10/lib/python3.10/site-packages/tortoise/models.py", line 1277, in all
db = using_db or cls._choose_db()
File "/Users/aaa/Library/Caches/pypoetry/virtualenvs/rearq-test-5bSWUw0w-py3.10/lib/python3.10/site-packages/tortoise/models.py", line 1033, in _choose_db
db = router.db_for_read(cls)
File "/Users/aaa/Library/Caches/pypoetry/virtualenvs/rearq-test-5bSWUw0w-py3.10/lib/python3.10/site-packages/tortoise/router.py", line 36, in db_for_read
return self._db_route(model, "db_for_read")
File "/Users/aaa/Library/Caches/pypoetry/virtualenvs/rearq-test-5bSWUw0w-py3.10/lib/python3.10/site-packages/tortoise/router.py", line 31, in _db_route
return connections.get(self._router_func(model, action))
File "/Users/aaa/Library/Caches/pypoetry/virtualenvs/rearq-test-5bSWUw0w-py3.10/lib/python3.10/site-packages/tortoise/router.py", line 18, in _router_func
for r in self._routers:
TypeError: 'NoneType' object is not iterable
"""
from rearq.
你试试最新的dev代码
from rearq.
解决了,打开方式不对,相关提示留给后来人。
一是要注意在fastapi里mount_app时候的执行顺序,需要先register_tortoise
二是注意在数据库的config字典的填写方式,apps里面必须有个app叫rearq,connection的名字可以随便起。
再次感谢。
from rearq.
好的
from rearq.
Related Issues (14)
- 有一个类似的darq HOT 2
- Motivation & Comparisons? HOT 2
- is ready for production ? HOT 1
- Cannot connect to remote redis HOT 2
- An error will be reported regardless of the name used HOT 1
- How to add corn tasks dynamically? HOT 3
- job.result() return ValidationError HOT 1
- 如何实现如arq本地不用定义函数? HOT 3
- Will jobs will be called more than once?
- aioredis.errors.AuthError: NOAUTH Authentication required.
- aioredis.errors.ReplyError: ERR unknown command 'XGROUP' HOT 1
- rearq docs HOT 2
- job_retry HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rearq.