dvadmin3_celery
介绍
dvadmin3-celery 插件是集成 django-celery-beat、tenant-schemas-celery、django-redis、django-celery-results 的一个后端插件,
安装可快速使用异步任务,包含在线添加任务、启停任务、查看任务记录等功能。
与之相对应的是 dvadmin3-celery-web 前端插件
安装包
目录结构:
dvadmin-celery
| dvdadmin_celery
| | fixtures
| | | __init__.py
| | | init_menu.json
| | | initialize.py
| | views
| | | __init__.py
| | | crontab_schedule.py
| | | interval_schedule.py
| | | periodic_task.py
| | | task.py
| | | task_detail.py
| | __init__.py
| | admin.py
| | apps.py
| | settings.py
| | tasks.py
| | urls.py
| setup.py
方式一: 一键导入注册配置
在 application / settings.py 插件配置中下导入默认配置
...
from dvadmin3_celery.settings import *
方式二: 手动配置
在INSTALLED_APPS 中注册app(注意先后顺序)
INSTALLED_APPS = [
...
'django_celery_beat',
'django_celery_results',
'dvadmin3_celery',
]
在 application / urls.py 中注册url地址
urlpatterns = [
...
path(r'api/dvadmin_celery/', include('dvadmin3_celery.urls')),
]
如果没有系统redis,请启动redis并添加配置 (./conf/env.example.py 及 ./conf/env.py中添加如下配置)
# redis 配置
REDIS_PASSWORD = '' # 如果没密码就为空
REDIS_HOST = '127.0.0.1'
REDIS_URL = f'redis://:{REDIS_PASSWORD or ""}@{REDIS_HOST}:6379'
在 application / settings.py 下添加配置
...
CACHES = { # 配置缓存
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f'{REDIS_URL}/1', # 库名可自选1~16
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
}
BROKER_URL = f'{REDIS_URL}/2' # 库名可自选1~16
CELERY_RESULT_BACKEND = 'django-db' # celery结果存储到数据库中
CELERYBEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler' # Backend数据库
进行迁移及初始化
python3 manage.py migrate
# 注意备份初始化信息
python3 manage.py init -y
其他配置请参考 django_celery_beat 和 celery 文档
使用说明
mac/linux:
celery -A application.celery worker -B --loglevel=info
win:
需要安装: pip install eventlet,需要启动两个程序(worker + beat 顺序不分先后)
celery -A application.celery worker -P eventlet --loglevel=info
celery -A application.celery beat --loglevel=info
注意
如果 celery worker 报错 KeyError,可尝试在django_vue_admin/application/celery.py文件里将
app = Celery(f"application")
改为
app = Celery(f"application", include=['dvadmin_celery.tasks'])
再重启尝试
redis下载地址:
Mac/Linux下载 http://download.redis.io/releases/
Windows下载 https://github.com/tporadowski/redis/releases/
Metadata
Release files for dvadmin3-celery 3.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dvadmin3-celery-3.1.7.tar.gz | 25.2 kB | Without provenance | Details for dvadmin3-celery-3.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dvadmin3_celery-3.1.7-py3-none-any.whl | Python 3 | none | any | Details for dvadmin3_celery-3.1.7-py3-none-any.whl |
Total release size: 56.4 kB
Release files / dvadmin3-celery-3.1.7.tar.gz
| Download URL | dvadmin3-celery-3.1.7.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7eb78898491f38eb86762318abd2227e3aef2fdb4785a2fc65493ef5657d15a
|
|
BLAKE2b-256 checksum How to use checksums |
2585f11e4edd7593abc8c142521d5f867b2db011d24b9990182de8694d4e34b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.7
|
Release files / dvadmin3_celery-3.1.7-py3-none-any.whl
| Download URL | dvadmin3_celery-3.1.7-py3-none-any.whl |
|---|---|
| Size | 31.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
08f22471d5eff1f4c9736a2f7a06c0d20bfcb2fba41c43f699a19b4077e2be07
|
|
BLAKE2b-256 checksum How to use checksums |
c52d2bfcfddf5b876e89abfb3a0e8b650b0a7b29d39a0cb2c0ebcb7634809f2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.7
|
Security for dvadmin3-celery 3.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.