class SchedulerTest(TestCase): def setUp(self): self.scheduler = Scheduler() self.tz = tz.gettz('Asia/Chongqing') def tearDown(self): self.scheduler = None def testRunJob(self): trigger = IntervalTrigger({}, minutes=5, timezone=self.tz) url = 'http://t.cn' job = Job(3, trigger, url) run_times = [] self.scheduler._run_job(job, run_times) def testUpdateJob(self): trigger = IntervalTrigger({}, minutes=5, timezone=self.tz) url = 'http://t.cn' job = Job(3, trigger, url) change_type = 'add' self.scheduler._update_job(job, change_type)
def handle(self, *args, **options): #logger = logging.getLogger('cron.backend') logger = logging.getLogger(__name__) fhd = logging.FileHandler('/tmp/cron_webdev_com_backend.log') fhd.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) logger.addHandler(fhd) logger.setLevel(logging.DEBUG) print "scheduler is preparing..." scheduler = Scheduler(standalone=False, timezone='Asia/Chongqing') scheduler.add_listener(self.job_success, EVENT_JOB_EXECUTED) scheduler.add_listener(self.job_failed, EVENT_JOB_ERROR) scheduler.add_listener(self.job_missed, EVENT_JOB_MISSED) print "scheduler is prepared" try: print "scheduler is starting..." logger.info('scheduler is starting...') scheduler.start() print "scheduler started" logger.info('scheduler is started...') while True: time.sleep(100) except (KeyboardInterrupt, SystemExit): scheduler.shutdown() logger.info("shutdown by Ctrl^C or exit signal") except Exception as e: logger.error(e) pass
def setUp(self): self.scheduler = Scheduler() self.tz = tz.gettz('Asia/Chongqing')