<s> import logging ; _L = logging . getLogger ( '<STR_LIT>' ) <EOL> from os import environ <EOL> from time import sleep , time <EOL> from boto import connect_cloudwatch <EOL> from . import ( <EOL> db_connect , db_queue , TASK_QUEUE , DONE_QUEUE , DUE_QUEUE , load_config , <EOL> pop_task_from_donequeue , pop_task_from_duequeue , setup_logger , <EOL> HEARTBEAT_QUEUE , flush_heartbeat_queue , get_recent_workers <EOL> ) <EOL> def main ( ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> setup_logger ( environ . get ( '<STR_LIT>' ) ) <EOL> config = load_config ( ) <EOL> checkin_time = time ( ) <EOL> try : <EOL> cw = connect_cloudwatch ( ) <EOL> except : <EOL> cw = False <EOL> while True : <EOL> try : <EOL> with db_connect ( config [ '<STR_LIT>' ] ) as conn : <EOL> task_Q = db_queue ( conn , TASK_QUEUE ) <EOL> done_Q = db_queue ( conn , DONE_QUEUE ) <EOL> due_Q = db_queue ( conn , DUE_QUEUE ) <EOL> beat_Q = db_queue ( conn , HEARTBEAT_QUEUE ) <EOL> pop_task_from_donequeue ( done_Q , config [ '<STR_LIT>' ] ) <EOL> pop_task_from_duequeue ( due_Q , config [ '<STR_LIT>' ] ) <EOL> flush_heartbeat_queue ( beat_Q ) <EOL> if time ( ) < checkin_time : <EOL> continue <EOL> with beat_Q as db : <EOL> recent_workers = get_recent_workers ( db ) <EOL> workers_n = sum ( map ( len , recent_workers . values ( ) ) ) <EOL> task_n , done_n , due_n = map ( len , ( task_Q , done_Q , due_Q ) ) <EOL> _L . info ( '<STR_LIT>' . format ( ** locals ( ) ) ) <EOL> if cw : <EOL> cw . put_metric_data ( '<STR_LIT>' , '<STR_LIT>' , task_n , unit = '<STR_LIT>' ) <EOL> cw . put_metric_data ( '<STR_LIT>' , '<STR_LIT>' , done_n , unit = '<STR_LIT>' ) <EOL> cw . put_metric_data ( '<STR_LIT>' , '<STR_LIT>' , due_n , unit = '<STR_LIT>' ) <EOL> cw . put_metric_data ( '<STR_LIT>' , '<STR_LIT>' , task_n + workers_n , unit = '<STR_LIT>' ) <EOL> cw . put_metric_data ( '<STR_LIT>' , '<STR_LIT>' , workers_n , unit = '<STR_LIT>' ) <EOL> checkin_time = time ( ) + <NUM_LIT:30> <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> _L . error ( '<STR_LIT>' , exc_info = True ) <EOL> sleep ( <NUM_LIT:5> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> exit ( main ( ) ) </s>
