Ejemplo n.º 1
0
def schedule_forever():
    """
    Schedules activities registration forever :)
    """
    while True:
        try:
            scheduler = Scheduler(time.time, time.sleep)
            schedule_activities(scheduler)
            scheduler.run()
        except Exception:
            logger.exception("Unhandled exception has occurred !")
Ejemplo n.º 2
0
def start_scheduler(scheduler: sched.scheduler) -> None:
    """Start the caching of every config file found in the app/config directory


    :param scheduler: scheduler object to use to schedule the caching
    :type scheduler: sched.scheduler
    """

    path = "app/config"
    files = [os.path.join(path, f) for f in os.listdir(path)
             if os.path.isfile(os.path.join(path, f)) and f.endswith('.json')]

    for file in files:
        with open(file, 'r') as config_file:
            config = json.loads(config_file.read())

        for entry in config:
            if 'cache' in entry:
                scheduler.enter(delay=0, priority=1, action=cache, argument=(entry, scheduler))

        if get_min_cache(file) < float('inf'):
            scheduler.enter(delay=get_min_cache(file)*60, priority=1, action=precompute, argument=(file, scheduler))

    scheduler.run()
Ejemplo n.º 3
0
	cursor.executemany('''
INSERT INTO spots VALUES (
	STRFTIME('%s', DATETIME(:timestamp)),
	:callsign,
	:mhz,
	:snr,
	:drift,
	:grid,
	:power,
	:reporter,
	:reporter_grid,
	:km,
	:az
)
	''', spots)
	connection.commit()
	connection.close()

if __name__ == '__main__':
	from sched import scheduler as Scheduler
	from time import time, sleep

	schedule = Scheduler(time, sleep)
	def run():
		write_data('spot-cache.db', spots())
		print("data written, next in {}s...".format(REPEAT))
		schedule.enter(REPEAT, 1, run)

	run()
	schedule.run()