Python3-apscheduler Module-Timing Scheduling

Source: Internet
Author: User
Tags sqlite

 fromApscheduler.schedulers.backgroundImportBackgroundscheduler, Blockingscheduler fromApscheduler.jobstores.redisImportRedisjobstore fromApscheduler.jobstores.sqlalchemyImportSqlalchemyjobstore fromApscheduler.executors.poolImportThreadpoolexecutor, ProcesspoolexecutordefPrint_args (*args):"""functions to be executed at timed:p Aram args: Parameters: Return:none"""     forArginchargs:Print(ARG)#There are two types of thread pool and process pool commonly used by actuatorsThread_pool = Threadpoolexecutor (30) Process_pool= Processpoolexecutor (5) Executors= {    'Thread': Thread_pool,'Process': Process_pool}#Memory is used by default, is insensitive to the loss of scheduled tasks, and requires low timing task executionRedis_store = Redisjobstore (host='172.16.120.120', port='6379') Sqlite_store= Sqlalchemyjobstore (url='Sqlite:///jobs.sqlite') Jobstores= {    'Redis': Redis_store,'default': Sqlite_store}#Delete a persisted scheduled task Redis_store.remove_all_jobs ()#Scheduler#Scheduler ConfigurationJob_defaults = {    'COALESCE': False,'max_instances': 5,    'Misfire_grace_time': 60}#COALESCE: When for some reason a job has accumulated several times without actually running (for example, the system hangs for 5 minutes after the recovery, there is a task to run every minute, according to the reason that the 5 minutes originally "plan" Run 5 times, but actually did not execute), If coalesce is true, the next time the job is put to executor, it will only execute 1 times, that is, the last time, if false, then it will be executed 5 times (not necessarily, because there are other conditions, look at the back Misfire_grace_ Explanation of time)#Max_instance: That is, the same job at the same time at most a few instances run, such as a 10-minute job, is specified to run 1 times per minute, if we max_instance value is 5, then on the 6th to 10th minute, the new running instance will not be executed, Because there are already 5 instances running.#Misfire_grace_time: Imagine a scenario similar to the above coalesce, if a job would have been executed 14:00, but for some reason was not scheduled, and now 14:01, when the 14:00 running instance was submitted, Will check the difference between the time it was scheduled to run and the current time (here is 1 minutes), which is greater than the 30-second limit we set, then the running instance will not be executed. #Scheduler = Blockingscheduler (Jobstores=jobstores, Executors=executors, Job_defaults=job_defaults, daemonic= False) # Instantiates a timed Task Scheduler object (blocking mode)Scheduler = Backgroundscheduler (Jobstores=jobstores, Executors=executors, Job_defaults=job_defaults, Daemonic=False )#instantiate a Scheduled Task schedule object (non-blocking mode)Scheduler.add_job (id='My_job_id1', jobstore='Redis', executor='Processpool', Func=print_args, args=["hello,world!"], trigger='Date', run_date='2018-06-18 12:56:00')#represents the execution at 2018-06-18 12:56:00#Trigger#three modes of execution trigger= ' date ' trigger= ' interval ' trigger= ' cron '#1.date Scheduled schedule is executed once by default timeScheduler.add_job (Func=print_args, args=["hello,world!"], trigger='Date', run_date='2018-06-18 12:56:00')#represents the execution at 2018-06-18 12:56:00#2.interval interval scheduling repeat execution at specified intervalsScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='interval', days=3, hours=17, minutes=19,seconds=7)#indicates that a task is performed every 3 days, 17:19 07 secondsScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='interval', Hours=17, minutes=19,seconds=7)#indicates that a task is performed every 17:19 07 secondsScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='interval', minutes=19, seconds=7)#indicates that a task is performed every 19 minutes and 07 secondsScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='interval', minutes=19)#indicates that a task is performed every 19 minutesScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='interval', Seconds=1)#indicates that a task is performed once per secondScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='interval', seconds=0.5)#indicates that a task is performed every 500 milliseconds#3. Cron Timing Schedule (Specify time to execute)#[parameter value range]#year (INT|STR) –4-digit-(represents four-digit years, such as 2008)#month (INT|STR) –month (1-12)-(indicates a value range of January-December)#Day (INT|STR) –day of the (1-31)-(indicates a value range of 1-31 days)#Week (INT|STR)-ISO week (1-53)-(Gregorian calendar December 31, 2006 can be written as 2006-w52-7 (extended form) or 2006w527 (compact form))#Day_of_week (INT|STR) –number or name of weekday (0-6 or Mon,tue,wed,thu,fri,sat,sun)-(indicates the day of the week, which can be either 0-6 or English Write representation)#Hour (INT|STR) –hour (0-23)-(indicates a value range of 0-23)#minute (INT|STR) –minute (0-59)-(indicates a value range of 0-59 points)#second (INT|STR) –second (0-59)-(indicates a value range of 0-59 seconds)#start_date (DATETIME|STR) –earliest possible date/time to trigger on (inclusive)-(indicates start time)#end_date (DATETIME|STR) –latest possible date/time to trigger on (inclusive)-(indicates end time)#timezone (DATETIME.TZINFO|STR) –time zone to use for the Date/time calculations (defaults to Scheduler timezone)-(table Time zone values are shown)#[parameter value format]#* Any fire on every value such as: day= ' * ' i.e., daily execution#*/a Any fire every a values, starting from the minimum such as: hour= ' */2 ' i.e., every two hours#A-B any fire on any value within the-a-range (a must be smaller than B) such as: minute= ' 6-8,21-23 ' i.e., 6-8 points and 21 -23-Point execution#a-b/c Any fire every C values within the A-B range such as: minute= ' 9-21/2 ' i.e., 9 points-21 points per two-hour execution#Xth y day fire on the x-th occurrence of weekday y within the month#Last x 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 # expressions with tease Number to separateScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='Cron', year=2018, Month=3, day=21, hour=21, minute=19, Second=8)#represents March 21, 2018 21:19 08 seconds executionScheduler.add_job (Func=print_args, args=['a','b','C'], trigger='Cron', day_of_week='Mon-fri', Hour=5, minute=30,start_date='2016-06-06', end_date='2018-08-08')#represents the Monday to Friday 5:30 execution, the effective date is 2016-06-06 00:00:00 to 2018-08-08 00:00:00Scheduler.add_job (Func=print_args, args=['a','b','C'], trigger='Cron', second='*/10')#indicates that the program executes once every 10 seconds, equivalent to seconds = ten in the interval interval scheduleScheduler.start ()#Start SchedulingScheduler.shutdown ()#Stop SchedulingScheduler.pause_job (job_id='my_job_id')#pausing a specified job scheduleScheduler.resume_job (job_id='my_job_id')#resume the specified job scheduleScheduler.pause ()#Pause SchedulingScheduler.resume ()#Recovery Schedule

Resources

Http://apscheduler.readthedocs.io/en/latest/userguide.html

Https://www.cnblogs.com/quijote/p/4385774.html

Python3-apscheduler Module-Timing Scheduling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.