Bijan
Bijan

Reputation: 8670

APScheduler Runs Job Twice

I have an APScheduler job that I want to run on Friday's at 8:05am with a jitter of 15minutes. Here is my code:

from apscheduler.schedulers.background import BackgroundScheduler
sched = BackgroundScheduler()

def WOL():
    requests.get("https://example.com/WOL")

sched.add_job(WOL, 'cron', hour=8, minute=5, jitter=900, day_of_week='fri')
sched.start()

try:
    while True:
        time.sleep(2)
except (KeyboardInterrupt, SystemExit):
    sched.shutdown()

However, this job runs twice. Here are the logs from today's run:

2024-01-05 08:04:17,657 - INFO - Running job "WOL (trigger: cron[day_of_week='fri', hour='8', minute='5'], next run at: 2024-01-05 08:13:47 PST)" (scheduled at 2024-01-05 08:04:17.646354-08:00)

2024-01-05 08:04:19,848 - INFO - Job "WOL (trigger: cron[day_of_week='fri', hour='8', minute='5'], next run at: 2024-01-05 08:13:47 PST)" executed successfully

2024-01-05 08:13:47,596 - INFO - Running job "WOL (trigger: cron[day_of_week='fri', hour='8', minute='5'], next run at: 2024-01-12 08:12:15 PST)" (scheduled at 2024-01-05 08:13:47.591469-08:00)

2024-01-05 08:13:49,608 - INFO - Job "WOL (trigger: cron[day_of_week='fri', hour='8', minute='5'], next run at: 2024-01-12 08:12:15 PST)" executed successfully

It ran at 8:04am and 8:13am. Am I doing something wrong with how I am scheduling it?

Upvotes: 1

Views: 201

Answers (0)

Related Questions