Skip to main content

适用于 django-vue-admin 的celery异步插件

Project description

dvadmin_celery

介绍

本包仅因为原仓库长期不更新而自行建库,并开源使用

dadmin-celery 插件是集成 django-celery-beat、tenant-schemas-celery、django-redis、django-celery-results 的一个后端插件, 安装可快速使用异步任务,包含在线添加任务、启停任务、查看任务记录等功能。
与之相对应的是 dvadmin-celery-web 前端插件

安装包

使用pip安装软件包:

pip install dadmin-celery

目录结构:

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 dvadmin_celery.settings import *

方式二: 手动配置

在INSTALLED_APPS 中注册app(注意先后顺序)

INSTALLED_APPS = [
    ...
    'django_celery_beat',
    'django_celery_results',
    'dvadmin_celery',
]

在 application / urls.py 中注册url地址

urlpatterns = [
    ...
    path(r'api/dvadmin_celery/', include('dvadmin_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 makemigrations 
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/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dadmin_celery-1.0.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dadmin_celery-1.0.3-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file dadmin_celery-1.0.3.tar.gz.

File metadata

  • Download URL: dadmin_celery-1.0.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.0

File hashes

Hashes for dadmin_celery-1.0.3.tar.gz
Algorithm Hash digest
SHA256 453db0a28a98dd51cac5463d7aa16030086a079e75327ee96d9500fb5d7a460d
MD5 92ac4d4d330dff18f7873ecef7d1a453
BLAKE2b-256 15bf944ce8a2bf45bd7d0105d606fdb08fdb69d63f51fdf37f1524522f359e3d

See more details on using hashes here.

File details

Details for the file dadmin_celery-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: dadmin_celery-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.0

File hashes

Hashes for dadmin_celery-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1a25c07780fc42c190efb42c9ac20ede304b8362e8270f87de058d299bb803de
MD5 71e7f30720433b146d1aceae21465a54
BLAKE2b-256 d13bc754a16248f82739e8c7ba6d9ab79d1b310067132a40235938ad860eb0fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page