V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
nekor
V2EX  ›  Python

Python 对 cron 表达式的支持,真的不是很好。

  •  
  •   nekor · 2019-06-19 19:37:31 +08:00 · 3227 次点击
    这是一个创建于 1765 天前的主题,其中的信息可能已经有所发展或是发生改变。

    公司需要使用定时任务,要求必须能输入标准的 cron 表达式,看了很多框架,都不支持标准的 6,7 位 cron 表达式,croniter,crontab,apscheduler 都是只支持 5 位的 cron 表达式。 问问各位大佬,这个需求能否实现?

    6 条回复    2019-06-20 16:24:44 +08:00
    jakezh
        1
    jakezh  
       2019-06-19 22:36:04 +08:00
    需求说一下啊 有什么特殊需求吗
    krixaar
        2
    krixaar  
       2019-06-20 09:09:55 +08:00
    apscheduler:
    class apscheduler.triggers.cron.CronTrigger(year=None, month=None, day=None, week=None, day_of_week=None, hour=None, minute=None, second=None, start_date=None, end_date=None, timezone=None, jitter=None)

    second minute hour day_of_week day month week year 这还不够用的吗?
    nekor
        3
    nekor  
    OP
       2019-06-20 09:32:34 +08:00
    @jakezh 很简单,输入‘ 0 15 10 ? * 6L ’这种类型的表达式,获取下次执行的日期时间
    nekor
        4
    nekor  
    OP
       2019-06-20 09:32:57 +08:00
    @krixaar 需要的是表达式这种形式,例如'0 15 10 ? * 6L'
    Takamine
        5
    Takamine  
       2019-06-20 11:31:13 +08:00
    要不自己写一个适配器开源出来阿。:doge:
    krixaar
        6
    krixaar  
       2019-06-20 16:24:44 +08:00
    你都有表达式了,按空格 split 一下填到对应项不就完事了?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3110 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:57 · PVG 18:57 · LAX 03:57 · JFK 06:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.