跳转到主要内容

基于Django的监控huey任务队列的工具:https://github.com/coleifer/huey

项目描述

django-huey-monitor

基于Django的监控huey任务队列的工具

当前实现将仅将所有Huey任务信号存储到数据库中,并在Django管理界面中显示。

tests codecov django-huey-monitor @ PyPi Python Versions License GPL-3.0-or-later

快速入门

pip install django-huey-monitor
INSTALLED_APPS = [
    #...
    'bx_django_utils', # https://github.com/boxine/bx_django_utils
    'huey_monitor',
    #...
]

注意:通常您不应该更改Huey任务。

收集主/子任务

Huey监控模型可以存储关于任务层次结构的信息。但此信息不能自动收集。您必须将这些信息存储在任务代码中。

例如。

@task(context=True)
def sub_task(task, parent_task_id, chunk_data):
    # Save the task hierarchy by:
    TaskModel.objects.set_parent_task(
        main_task_id=parent_task_id,
        sub_task_id=task.id,
    )
    # ... do something with e.g.: chunk_data ...


@task(context=True)
def main_task(task):
    for chunk_data in something:
        sub_task(parent_task_id=task.id, chunk_data=chunk_data)

工作示例可以在以下test app中找到: huey_monitor_tests/test_app/tasks.py

收集进度信息

正在运行的任务可以像tqdm一样存储进度信息。因此,可以在管理界面中看到进度。

最小示例

@task(context=True)
def foobar_task(task, list_to_process):
    process_info = ProcessInfo(
        task,
        desc='A description of this Job',
        total=len(list_to_process)
    )

    for item in list_to_process:
        # ...to something with the {item}...
        process_info.update(n=1) # add the information that one item was processed

也可以将工作分成几个任务,并收集主/子任务的处理信息。

工作示例可以在以下test app中找到: huey_monitor_tests/test_app/tasks.py

设置

覆盖列表过滤器(可选)

可以通过设置覆盖SignalInfoModelAdminTaskModelAdminlist_filter。例如:

HUEY_MONITOR_SIGNAL_INFO_MODEL_LIST_FILTER = ('task__name', 'signal_name')
HUEY_MONITOR_TASK_MODEL_LIST_FILTER = ('name', 'state__signal_name')

注意:这两个设置都是可选的。在这个示例中,“hostname”过滤器不存在;)

运行测试项目

注意:您可以使用测试项目快速测试Huey Monitor,例如

~/django-huey-monitor$ ./manage.sh run_testserver

或者在隔离的Docker容器中

~/django-huey-monitor$ make up

更多信息请见下文。

屏幕截图

(更多截图:boxine.github.io/django-huey-monitor/

2021-02-22-v030-task-details.png

2021-02-22-v030-task-details.png

2021-02-22-v030-progress-info1.png

2021-02-22-v030-progress-info1.png

开发中

  • 安装Docker
  • 克隆项目
  • 启动容器

要开始开发,例如:

~$ git clone https://github.com/boxine/django-huey-monitor.git
~$ cd django-huey-monitor
~/django-huey-monitor$ ./manage.py
~/django-huey-monitor$ make help
~/django-huey-monitor$ make up

将我们的浏览器指向:http://localhost:8000/

我们的Makefile包含以下目标

help                           List all commands
install                        install huey monitor package
update                         Update the dependencies as according to the pyproject.toml file
run-dev-server                 Run Django's developer server
test                           Run unittests
tox                            Run unittests via tox
makemessages                   Make and compile locales message files
clean                          Remove created files from the test project (e.g.: SQlite, static files)
build                          Update/Build docker services
up                             Start docker containers
down                           Stop all containers
shell-django                   go into a interactive bash shell in Django container
run-shell-django               Build and start the Django container and go into shell
shell-huey1                    go into a interactive bash shell in Huey worker container 1
shell-huey2                    go into a interactive bash shell in Huey worker container 2
shell-huey3                    go into a interactive bash shell in Huey worker container 3
shell-redis                    go into a interactive bash shell in Redis container
logs                           Display and follow docker logs
logs-django                    Display and follow docker logs only from "django" container
reload-django                  Reload the Django dev server
reload-huey                    Reload the Huey worker
restart                        Restart the containers
fire-test-tasks                Call "fire-test-tasks" manage command to create some Huey Tasks
fire-many-test-tasks           Call "fire-test-tasks" with --count 10000 to create many task entries ;)
fire-parallel-processing-task  Just fire "parallel processing" Huey Task
delete-all-tasks-data          Delete all Task/Signal database enties

也可以使用SQLite和Huey立即设置运行测试设置,无需Docker

~$ git clone https://github.com/boxine/django-huey-monitor.git
~$ cd django-huey-monitor
~/django-huey-monitor$ ./manage.py run_dev_server

不兼容的更改

版本兼容性

Huey Monitor Django Python
>v0.7.0 v3.2, v4.1, v4.2 v3.9, v3.10, v3.11
>v0.6.0 v3.2, v4.0, v4.1 v3.9, v3.10, v3.11
>v0.5.0 v2.2, v3.1, v3.2 v3.7, v3.8, v3.9
<=v0.4.0 v2.2, v3.0, v3.1 v3.7, v3.8, v3.9

v0.6.0

我们重构了项目设置:开发者必须重新初始化存储库。

v0.5.0

更改CI并删除对Django 3.0的测试,但添加Django v3.2的测试运行

v0.3.0 -> v0.4.0 - Django相关内容的外包

bx_py_utils已拆分,并将与Django相关的部分移动到:bx_django_utils

您必须更改Django设置并替换应用程序名称

 INSTALLED_APPS = [
     #...
-     'bx_py_utils',
+     'bx_django_utils',
     'huey_monitor',
     #...
 ]

历史记录

许可证

GPL. 欢迎补丁!

链接

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

django-huey-monitor-0.9.0.tar.gz (253.1 kB 查看哈希值

上传于 源码

构建版本

django_huey_monitor-0.9.0-py3-none-any.whl (68.5 kB 查看哈希)

上传于 Python 3

由...

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面