python apsheduler cron 参数解析
from:https://apscheduler.readthedocs.io/en/v2.1.2/cronschedule.html
Cron-style scheduling
This is the most powerful scheduling method available in APScheduler. You can specify a variety of different expressions on each field, and when determining the next execution time, it finds the earliest possible time that satisfies the conditions in every field. This behavior resembles the “Cron” utility found in most UNIX-like operating systems.
You can also specify the starting date for the cron-style schedule through the start_date parameter, which can be given as a date/datetime object or text. See the Date-based scheduling section for examples on that.
Unlike with crontab expressions, you can omit fields that you don’t need. Fields greater than the least significant explicitly defined field default to * while lesser fields default to their minimum values except for week and day_of_week which default to *. For example, if you specify onlyday=1, minute=20, then the job will execute on the first day of every month on every year at 20 minutes of every hour. The code examples below should further illustrate this behavior.
Note
The behavior for omitted fields was changed in APScheduler 2.0. Omitted fields previously always defaulted to *.
Available fields
| Field | Description |
|---|---|
| year | 4-digit year number |
| month | month number (1-12) |
| day | day of the month (1-31) |
| week | ISO week number (1-53) |
| day_of_week | number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun) |
| hour | hour (0-23) |
| minute | minute (0-59) |
| second | second (0-59) |
Note
The first weekday is always monday.
Expression types
The following table lists all the available expressions applicable in cron-style schedules.
| Expression | Field | Description |
|---|---|---|
| * | any | Fire on every value |
| */a | any | Fire every a values, starting from the minimum |
| a-b | any | Fire on any value within the a-b range (a must be smaller than b) |
| a-b/c | any | Fire every c values within the a-b range |
| xth y | day | Fire on the x -th occurrence of weekday y within the month |
| last x | day | Fire on the last occurrence of weekday x within the month |
| last | day | Fire on the last day within the month |
| x,y,z | any | Fire on any matching expression; can combine any number of any of the above expressions |
Example 1
from apscheduler.scheduler import Scheduler # Start the scheduler
sched = Scheduler()
sched.start() def job_function():
print "Hello World" # Schedules job_function to be run on the third Friday
# of June, July, August, November and December at 00:00, 01:00, 02:00 and 03:00
sched.add_cron_job(job_function, month='6-8,11-12', day='3rd fri', hour='0-3')
Example 2
# Initialization similar as above, the backup function defined elsewhere # Schedule a backup to run once from Monday to Friday at 5:30 (am)
sched.add_cron_job(backup, day_of_week='mon-fri', hour=5, minute=30)
Decorator syntax
As a convenience, there is an alternative syntax for using cron-style schedules. The cron_schedule()decorator can be attached to any function, and has the same syntax as add_cron_job(), except for the func parameter, obviously.
@sched.cron_schedule(day='last sun')
def some_decorated_task():
print "I am printed at 00:00:00 on the last Sunday of every month!"
If you need to unschedule the decorated functions, you can do it this way:
scheduler.unschedule_job(job_function.job)
python apsheduler cron 参数解析的更多相关文章
- Python命令行参数解析模块getopt使用实例
Python命令行参数解析模块getopt使用实例 这篇文章主要介绍了Python命令行参数解析模块getopt使用实例,本文讲解了使用语法格式.短选项参数实例.长选项参数实例等内容,需要的朋友可以参 ...
- python命令行参数解析OptionParser类用法实例
python命令行参数解析OptionParser类用法实例 本文实例讲述了python命令行参数解析OptionParser类的用法,分享给大家供大家参考. 具体代码如下: from opt ...
- python命令行参数解析模块argparse和docopt
http://blog.csdn.net/pipisorry/article/details/53046471 还有其他两个模块实现这一功能,getopt(等同于C语言中的getopt())和弃用的o ...
- Python命令行参数解析模块argparse
当写一个Python脚本时经常会遇到不同参数不同功能的情况,如何做一个更好看的命令帮助信息以及对命令参数解析呢? 这就需要使用argparse模块 #!/usr/bin/env python # -* ...
- Python 命令行参数解析工具 argparse
为什么需要argparse 开门见山,举一个简易计算器代码的例子,其中sys.argv用来读取脚本执行时后面传入的参数. def calculator(x, y, operation): if &qu ...
- Python 命令行参数解析
方法1: Python有一个类可以专门处理命令行参数,先看代码: #!/usr/bin/env python # encoding: utf-8 from optparse import Option ...
- python argparse(参数解析)模块学习(一)
class ArgumentParser(_AttributeHolder, _ActionsContainer): """Object for parsing comm ...
- python argparse(参数解析)模块学习(二)
转载自:http://www.cnblogs.com/fireflow/p/4841389.html(我去..没转载功能,ctrl + c 和 ctrl + v 得来的,格式有点问题,可去原版看看) ...
- 扩展Python模块系列(三)----参数解析与结果封装
在上一节中,通过一个简单的例子介绍了C语言扩展Python内建模块的整体流程,从本节开始讲开始深入讨论一些细节问题,在细节讨论中从始至终都会涉及[引用计数]的问题.首先讨论C语言封装的Python函数 ...
随机推荐
- 前端独立引用 ejs模版
ejs 用法不再多说,网自行查阅.一个是基于nodeJS平台运行的EJS,另外一个是在浏览器执行的EJS.这里要说的是html 独立引入ejs.min.js 使用的一个注意点. 如:index.htm ...
- OpenGL学习--06--键盘与鼠标交互
1.tutorial06.cpp // Include standard headers #include <stdio.h> #include <stdlib.h> // I ...
- 【Android】RxJava的使用(四)线程控制 —— Scheduler
并没有关系的图 前言 经过前几篇的介绍,对RxJava对模式有了一定的理解:由Observable发起事件,经过中间的处理后由Observer消费.(对RxJava还不了解的可以出门左拐)之前的代码中 ...
- Android 获取全局Context的技巧
回想这么久以来我们所学的内容,你会发现有很多地方都需要用到Context,弹出Toast的时候需要.启动活动的时候需要.发送广播的时候需要.操作数据库的时候需要.使用通知的时候需要等等等等.或许目前你 ...
- JVM知识(三):内存模型和可见性
这篇文章我们将根据JVM的内存模型探索java当中变量的可见性以及不同的java指令在并发时可能发生的指令重排序的情况.来聊聊java线程对一个变量的更新怎么通知另一个线程,及volatile的作用和 ...
- springboot学习入门之一---基本了解
1springboot基本了解 1.1概述 Spring Boot不是一门新技术,本质上就是spring. 特性: 1) 零配置(或很少配置) 2) 四个核心:(ASCA) 3.1)自动配置:spri ...
- linux 局域网探测工具nmap
NMap,也就是Network Mapper,是Linux下的网络扫描和嗅探工 具包,其基本功能有三个, 一是探测一组主机是否在线: 其次是扫描主机端口,嗅探所提供的网络服务: 还可以推断主机所用的操 ...
- C#自定义控件的创建
1.创建自定义控件 选择[经典桌面]——[窗体控件库] 2.添加控件,组合成一个新的控件 自定义控件功能:打开一张图片,将图片展示在pictureBox控件中,并将图片的名称.大小.尺寸显示出来 控件 ...
- Linux系统更改/关闭防火墙
更改/关闭防火墙 查看当前防火墙状态 /etc/init.d/iptables status ==>service iptables status 打开防火墙 service iptables ...
- java.lang.verifyerror:bad type on orerand stack
问题: junit测试的时候报这个错:java.lang.verifyerror:bad type on orerand stack 原因:(多种,自行逐个排查) 1.class not find 引 ...