Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APScheduler options

I'm trying to schedule programmatically some jobs with Advace Python Scheduler, my problem is that in the documentation it is only mentioned how to schedule with 'interval' trigger type, what about 'cron' and 'date'. Is there any complete documentation about scheduling options of APScheduler?

For instance:

#!/usr/bin/env python

from time import sleep 
from apscheduler.scheduler import Scheduler

sched = Scheduler()
sched.start()        

# define the function that is to be executed
def my_job(text):
    print text

job = sched.add_job(my_job, 'interval', id='my_job', seconds=10, replace_existing=True, args=['job executed!!!!'])

while True:
        sleep(1)

How I can schedule based on 'date' or 'cron'

I'm using latest APScheduler version 3.0.2

Thanks

like image 702
tbo Avatar asked Apr 03 '15 09:04

tbo


People also ask

What is Max_instances in APScheduler?

The max_instances only tells you how many concurrent jobs you can have. APScheduler has three types of triggers: date interval cron. interval and cron repeat forever, date is a one-shot on a given date.

How does APScheduler work?

APScheduler provides many different ways to configure the scheduler. You can use a configuration dictionary or you can pass in the options as keyword arguments. You can also instantiate the scheduler first, add jobs and configure the scheduler afterwards. This way you get maximum flexibility for any environment.

How do I stop APScheduler?

It only stops when you type Ctrl-C from your keyboard or send SIGINT to the process. This scheduler is intended to be used when APScheduler is the only task running in the process. It blocks all other code from running unless the others are running in separated threads.

What is background scheduler?

BackgroundScheduler is a scheduler provided by APScheduler that runs in the background as a separate thread. Below is an example of a background scheduler. import time from datetime import datetime from apscheduler.


1 Answers

sched.add_job(my_job, trigger='cron', hour='22', minute='30')

Means call function 'my_job' once every day on 22:30.

APScheduler is a good stuff, but lack of docs, which is a pity, you can read the source codes to learn more.

There is some more tips for you:

  1. use *

    sched.add_job(my_job, trigger='cron', second='*') # trigger every second.
    
  2. some more attributes

    {'year': '*', 'month': 1, 'day': 1, 'week': '*', 'day_of_week': '*', 'hour': 0, 'minute': 0, 'second': 0}
    

And in my opinion, cron job can replace date jobs in most situations.

like image 112
flycee Avatar answered Sep 22 '22 06:09

flycee