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")
时间: 2024-10-29 19:10:56

APScheduler API -- apscheduler.triggers.interval的相关文章

APScheduler API -- apscheduler.triggers.date

apscheduler.triggers.date API Trigger alias for add_job(): date class apscheduler.triggers.date.DateTrigger(run_date=None, timezone=None) Bases: apscheduler.triggers.base.BaseTrigger Triggers once on the given datetime. If run_date is left empty, cur

APScheduler API -- apscheduler.schedulers.base

apscheduler.schedulers.base API class apscheduler.schedulers.base.BaseScheduler(gconfig={}, **options) Abstract base class for all schedulers. Takes the following keyword arguments: Parameters: logger (str|logging.Logger) – logger to use for the sche

APScheduler API

apscheduler.triggers.cron API Trigger alias for add_job(): cron 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=No

APScheduler 3.0.1浅析

简介 APScheduler是一个小巧而强大的Python类库,通过它你可以实现类似Unix系统cronjob类似的定时任务系统.使用之余,阅读一下源码,一方面有助于更好的使用它,另一方面,个人认为aps的架构设计质量很高,阅读它对于提升软件开发的sense很有帮助. 组成 APScheduler整个系统可以说由这五个概念组成: scheduler:控制器,可以看做整个系统的driver,外部世界通过它来实现任务(Job)的增删改查管理.根据IO模式的不同,aps提供了多种scheduler实现

apscheduler 绿色版

由于依赖EntryPoint,因此apscheduler在离线的方式(直接拷贝然后引用)使用时,会报错. 错误信息类似: No trigger by the name “interval/cron/date” was found 原因: 基类的构造函数依赖于EntryPoint, 如下: class BaseScheduler(six.with_metaclass(ABCMeta)): //... _trigger_plugins = dict((ep.name, ep) for ep in i

定时任务框架APScheduler学习详解

APScheduler简介 在平常的工作中几乎有一半的功能模块都需要定时任务来推动,例如项目中有一个定时统计程序,定时爬出网站的URL程序,定时检测钓鱼网站的程序等等,都涉及到了关于定时任务的问题,第一时间想到的是利用time模块的time.sleep()方法使程序休眠来达到定时任务的目的,虽然这样也可以,但是总觉得不是那么的专业,^_^所以就找到了python的定时任务模块APScheduler: APScheduler基于Quartz的一个Python定时任务框架,实现了Quartz的所有功

Flask(十一)flash与APScheduler 实现定时任务

from flask import Flask from flask_apscheduler import APScheduler # 引入APScheduler class Config(object): # 创建配置,用类 JOBS = [ # 任务列表 { # 任务字典(细节) 'id': 'job1', 'func': '__main__:job_1', 'args': (1, 2), 'trigger': 'cron', 'hour': 19, 'minute': 27 }, { #

Flask+APScheduler定时任务

1.安装依赖 pip install flask_apscheduler 2.使用定时任务 from flask import Flask from flask_apscheduler import APScheduler # 引入APScheduler #任务配置类 class SchedulerConfig(object): JOBS = [ { 'id': 'print_job', # 任务id 'func': '__main__:print_job', # 任务执行程序 'args':

APScheduler轻量级定时任务框架

目录 一.APScheduler简介 支持的后端存储作业 集成的Python框架 二.APScheduler下载安装 三.APScheduler组件 各组件简介 调度器 作业存储器 执行器 触发器 四.使用 添加任务 指定时间执行任务,只执行一次 间隔时间执行任务 一.APScheduler简介 APScheduler(Advanced Python Scheduler)是一个轻量级的Python定时任务调度框架(Python库). APScheduler有三个内置的调度系统,其中包括: cro