Beispiel #1
0
 def test_add_and_cancel_job(self):
     cron = Cron()
     cron.add_job('cron_job', 'every 5')
     self.assertEqual(Thing('job').find('cron_job').name, 'cron_job')
     cron.cancel_job('cron_job')
     self.assertEqual(Thing('job').find('cron_job'), None)
Beispiel #2
0
def setdebug(debug=False):
    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        filemode='a+')


if __name__ == '__main__':
    setdebug(False)
    db.setup('localhost',
             'test',
             'test',
             'leaf',
             pool_opt={
                 'minconn': 3,
                 'maxconn': 10
             })
    thing_setup()
    next_run = datetime.now() - timedelta(minutes=10)
    for cron_id in range(4, 11):
        name = 'name_' + str(cron_id)
        job = Job(cron_id, None, name, event='every 2', next_run=next_run)
        Thing('job').save(job)
    time.sleep(2)
    try:
        cron = Cron(5)
        cron.run()
    except KeyboardInterrupt:
        exit(1)
Beispiel #3
0
from leaf import db
from leaf.thing import Thing, thing_setup
from leaf.model import Job
from leaf.cron import Cron
from datetime import datetime, timedelta
import time
import logging

def setdebug(debug=False):
    level = logging.DEBUG if debug else logging.INFO
    logging.basicConfig(level=level,
                        format='%(asctime)s %(levelname)-8s %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S', filemode='a+')


if __name__ == '__main__':
    setdebug(False)
    db.setup('localhost', 'test', 'test', 'leaf', pool_opt={'minconn':3, 'maxconn':10})
    thing_setup()
    next_run = datetime.now() - timedelta(minutes=10)
    for cron_id in range(4, 11):
        name = 'name_'  + str(cron_id)
        job = Job(cron_id,None, name, event='every 2', next_run=next_run)
        Thing('job').save(job)
    time.sleep(2)
    try:
        cron = Cron(5)
        cron.run()
    except KeyboardInterrupt:
        exit(1)