Beispiel #1
0
 def run( self ):
     throttle = LocalThrottle( min_interval=self.options.interval )
     # First call always returns immediately
     throttle.throttle( )
     # Always update keys initially
     self.update_ssh_keys( )
     self.start_metric_thread( )
     while True:
         # Do 'long' (20s) polling for messages
         messages = self.queue.get_messages( num_messages=10,  # the maximum permitted
                                             wait_time_seconds=20,  # ditto
                                             visibility_timeout=10 )
         if messages:
             # Process messages, combining multiple messages of the same type
             update_ssh_keys = False
             for sqs_message in messages:
                 try:
                     message = Message.from_sqs( sqs_message )
                 except UnknownVersion as e:
                     log.warning( 'Ignoring message with unkown version' % e.version )
                 else:
                     if message.type == Message.TYPE_UPDATE_SSH_KEYS:
                         update_ssh_keys = True
             if update_ssh_keys:
                 self.update_ssh_keys( )
                 # Greedily consume all accrued messages
             self.queue.delete_message_batch( messages )
         else:
             # Without messages, update if throttle interval has passed
             if throttle.throttle( wait=False ):
                 self.update_ssh_keys( )
Beispiel #2
0
 def run( ):
     log.info( "Entering main loop." )
     ctx = Context( availability_zone=options.availability_zone, namespace=options.namespace )
     throttle = LocalThrottle( min_interval=options.interval )
     for i in itertools.count( ):
         throttle.throttle( )
         try:
             log.info( "Starting run %i.", i )
             Agent( ctx, options ).run( )
             log.info( "Completed run %i.", i )
         except (SystemExit, KeyboardInterrupt):
             log.info( 'Terminating.' )
             break
         except:
             log.exception( 'Abandoning run due to exception' )
Beispiel #3
0
 def run():
     log.info("Entering main loop.")
     ctx = Context(availability_zone=options.availability_zone,
                   namespace=options.namespace)
     throttle = LocalThrottle(min_interval=options.interval)
     for i in itertools.count():
         throttle.throttle()
         try:
             log.info("Starting run %i.", i)
             Agent(ctx, options).run()
             log.info("Completed run %i.", i)
         except (SystemExit, KeyboardInterrupt):
             log.info('Terminating.')
             break
         except:
             log.exception('Abandoning run due to exception')