zoukankan      html  css  js  c++  java
  • APScheduler API -- apscheduler.triggers.interval

    apscheduler.triggers.interval

    API

    Trigger alias for add_job(): interval

    class apscheduler.triggers.interval.IntervalTrigger(weeks=0, days=0, hours=0, minutes=0, seconds=0, start_date=None, end_date=None, timezone=None)

    Bases: apscheduler.triggers.base.BaseTrigger

    Triggers on specified intervals, starting on start_date if specified, datetime.now() + interval otherwise.

    Parameters:
    • weeks (int) – number of weeks to wait
    • days (int) – number of days to wait
    • hours (int) – number of hours to wait
    • minutes (int) – number of minutes to wait
    • seconds (int) – number of seconds to wait
    • start_date (datetime|str) – starting point for the interval calculation
    • end_date (datetime|str) – latest possible date/time to trigger on
    • timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations

    Introduction

    This method schedules jobs to be run periodically, on selected intervals.

    You can also specify the starting date and ending dates for the schedule through the start_date and end_date parameters, respectively. They can be given as a date/datetime object or text (in the ISO 8601 format).

    If the start date is in the past, the trigger will not fire many times retroactively but instead calculates the next run time from the current time, based on the past start time.

    Examples

    from datetime import datetime
    
    from apscheduler.scheduler import BlockingScheduler
    
    
    def job_function():
        print("Hello World")
    
    sched = BlockingScheduler()
    
    # Schedule job_function to be called every two hours
    sched.add_job(job_function, 'interval', hours=2)
    
    sched.start()
    

    You can use start_date and end_date to limit the total time in which the schedule runs:

    # The same as before, but starts on 2010-10-10 at 9:30 and stops on 2014-06-15 at 11:00
    sched.add_job(job_function, 'interval', hours=2, start_date='2010-10-10 09:30', end_date='2014-06-15 11:00)
    

    The scheduled_job() decorator works nicely too:

    from apscheduler.scheduler import BlockingScheduler
    
    @sched.scheduled_job('interval', id='my_job_id', hours=2)
    def job_function():
        print("Hello World")
    
  • 相关阅读:
    preg_match正则匹配的字符串长度问题
    jquery获得select option的值 和对select option的操作
    一笔一划画蜻蜓
    PHPMyadmin 配置文件详解(配置)
    用smarty产生随机数
    svn提交后测试网站自动发布的配置
    linux打包压缩命令汇总
    HR 业务相关
    ABAP中TYPES与DATA、TYPE与LIKE 区别
    HRinfotype增强笔记(转)
  • 原文地址:https://www.cnblogs.com/fendou-999/p/3935663.html
Copyright © 2011-2022 走看看