def control_loop():
set_service_status(Service.SCHEDULE, ServiceStatus.BUSY)<EOL>notify.notify('<STR_LIT>')<EOL>while not terminate():<EOL><INDENT>notify.notify('<STR_LIT>')<EOL>get_schedule()<EOL>session = get_session()<EOL>next_event = session.query(UpcomingEvent).filter(UpcomingEvent.end > timestamp()).order_by(UpcomingEvent.start).first()<EOL>if next_event:<EOL><INDENT>logger.info('<STR_LIT>',<EOL>datetime.fromtimestamp(next_event.start))<EOL>notify.notify('<STR_LIT>' %<EOL>datetime.fromtimestamp(next_event.start))<EOL><DEDENT>else:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>notify.notify('<STR_LIT>')<EOL><DEDENT>session.close()<EOL>next_update = timestamp() + config()['<STR_LIT>']['<STR_LIT>']<EOL>while not terminate() and timestamp() < next_update:<EOL><INDENT>time.sleep(<NUM_LIT:0.1>)<EOL><DEDENT><DEDENT>logger.info('<STR_LIT>')<EOL>set_service_status(Service.SCHEDULE, ServiceStatus.STOPPED)<EOL>
Main loop, retrieving the schedule.