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, current time is used.

Parameters:
  • run_date (datetime|str) – the date/time to run the job at
  • timezone (datetime.tzinfo|str) – time zone for run_date if it doesn’t have one already

Introduction

This is the simplest possible method of scheduling a job. It schedules a job to be executed once at the specified time. It is APScheduler’s equivalent to the UNIX “at” command.

The run_date can be given either as a date/datetime object or text (in the ISO 8601 format).

Examples

from datetime import date

from apscheduler.scheduler import BlockingScheduler sched = BlockingScheduler() def my_job(text): print(text) # The job will be executed on November 6th, 2009 sched.add_job(my_job, 'date', run_date=date(2009, 11, 6), args=['text']) sched.start() 

You can specify the exact time when the job should be run:

# The job will be executed on November 6th, 2009 at 16:30:05
sched.add_job(my_job, 'date', run_date=datetime(2009, 11, 6, 16, 30, 5), args=['text']) 

The run date can be given as text too:

sched.add_job(my_job, 'date', run_date='2009-11-06 16:30:05', args=['text']) 

To add a job to be run immediately:

# The 'date' trigger and datetime.now() as run_date are implicit
sched.add_job(my_job, args=['text']) 

转载于:https://www.cnblogs.com/fendou-999/p/3935660.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值