Python定時任務架構APScheduler 3.0.3 Cron樣本

來源:互聯網
上載者:User

標籤:

APScheduler是基於Quartz的一個Python定時任務架構,實現了Quartz的所有功能,使用起來十分方便。提供了基於日期、固定時間間隔以及crontab類型的任務,並且可以持久化任務。基於這些功能,我們可以很方便的實現一個python定時任務系統

安裝

安裝過程很簡單,可以基於pip和源碼。

Pip install apscheduler==3.0.3

或者下載源碼,運行命令:

Python setup.py install

cron job例子
   1:  #coding=utf-8
   2:  from apscheduler.schedulers.blocking import BlockingScheduler
   3:  from datetime import datetime
   4:  import time
   5:  import os
   6:     
   7:  def tick():
   8:      print(‘Tick! The time is: %s‘ % datetime.now())
   9:   
  10:  if __name__ == ‘__main__‘:
  11:      scheduler = BlockingScheduler()
  12:      scheduler.add_job(tick,‘cron‘, second=‘*/3‘, hour=‘*‘)    
  13:      print(‘Press Ctrl+{0} to exit‘.format(‘Break‘ if os.name == ‘nt‘ else ‘C‘))
  14:      try:
  15:          scheduler.start()
  16:      except (KeyboardInterrupt, SystemExit):
  17:          scheduler.shutdown() 
  18:   
  19:   
  20:   
Cron表達 式說明

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

Python定時任務架構APScheduler 3.0.3 Cron樣本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.