Skip to main content

轻量级的 Django 定时任务调度框架,基于数据库锁实现进程/线程级调度与日志记录。

Project description

DjangoSched

轻量级的 Django 定时任务调度框架。基于 Django ORM 与线程/进程实现,支持:

  • 周期任务调度、任务运行日志(SchedulerLog)和锁竞争机制;
  • 嵌入式线程或独立进程运行调度器;
  • 与 Django Admin 集成查看调度器与运行日志。

核心实现与入口

快速开始

  1. 安装(在虚拟环境中):
pip install -e .
  1. 在 Django 项目里加入 django_schedINSTALLED_APPS(示例项目在 demo 中):
INSTALLED_APPS = [
    # ...
    'django_sched',
]
  1. 迁移并启动:
python manage.py migrate
python manage.py runserver

runservergunicorn 下,应用会通过 DjangoSchedConfig.ready() 自动尝试启动调度器(可在日志中看到启动/竞态信息)。详情见 django_sched.apps.DjangoSchedConfig.ready

以编程方式启动(例如在管理命令中):

from django_sched.sched import start_scheduler
# 在当前进程中以嵌入方式启动(会阻塞)
start_scheduler(embedded_process=True)
# 或作为线程/进程嵌入
start_scheduler(thread=True)

注意事项

  • 锁机制基于数据库表 django_sched_scheduler,当检测到上次持有进程心跳过期时会尝试接管锁;
  • 默认 timezone 配置会影响锁过期与日志时间,请根据项目配置调整;
  • Admin 页面禁止手动新增/修改/删除日志。

贡献与授权

  • 许可:MIT(见 LICENSE)
  • 欢迎提 issue / PR

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

django_sched-0.1.3.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

django_sched-0.1.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file django_sched-0.1.3.tar.gz.

File metadata

  • Download URL: django_sched-0.1.3.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.14

File hashes

Hashes for django_sched-0.1.3.tar.gz
Algorithm Hash digest
SHA256 100b9cf2691988975e6f9fa0e1256ff990938558153772d0b0723b9127506bbc
MD5 1fc42d04ef7d52853bb45933a7b63c4d
BLAKE2b-256 13c910c5cbdcab937f7c8567187068e1d147681a6c2f749a9803208b025b0aa8

See more details on using hashes here.

File details

Details for the file django_sched-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_sched-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d832d34cf432d83199e9426d02f75fb686b0cac26d7699326234a16a31d6788d
MD5 02f87c1af4a117f84caf08d8f15c48ba
BLAKE2b-256 33642704a28e544b4d9fc5c7082dcb6fddcb5c379be43cf5e8c3285a626c4584

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