0

I'm trying to use the APScheduler library to execute a job at two certain times: 1am PST and 2am PST.

Sort of lost, I am trying to figure out what am doing wrong. Here is my code so far:

#!/usr/bin/python

import sys
import re
import urllib
import csv
import urllib2
import logging

import datetime

from apscheduler.schedulers.blocking import BlockingScheduler


sched = BlockingScheduler()
logging.basicConfig()

def main():    
  #Make a rest call, store the output in a csv, close the file.
  ...
  f.close()

sched.add_job(my_job, 'date', run_date = '2015-12-15 01:00:00', args=['text'])

try:
    sched.start()
    print(datetime.datetime.now())

except (KeyboardInterrupt):
    logger.debug('Terminating...')
    print (datetime.datetime.now())

The current time is 12:16 PST, I just ran the above script and it executed and created the file prior to the job time of 12:30:30pm; this is for testing purposes.

So, I'm trying to figure out what I am doing wrong with regards to using APScheduler.

I want to improve this code, what are some things I can change?

user2578013
  • 73
  • 2
  • 4
  • 12

1 Answers1

0

If you want to run your code at certain times every time, you should be using the cron trigger:

sched.add_job(my_job, 'cron', hour='1,2', args=['text'])

For better debugging:

logging.basicConfig(level=logging.DEBUG)
Alex Grönholm
  • 5,563
  • 29
  • 32