def run(self): start = int(time.time()) end = start + self.interval now = start while now < end: # Sleep for short periods in an attempt to not get too skewed time.sleep(30) now = int(time.time()) stoneridge.enqueue(srid=self.srid, nightly=self.nightly, ldap=self.ldap, sha=self.sha, netconfigs=self.netconfigs, operating_systems=self.operating_systems, attempt=self.attempt)
def main(): parser = stoneridge.ArgumentParser() parser.parse_args() root = stoneridge.get_config('enqueuer', 'root') username = stoneridge.get_config('enqueuer', 'username') password = stoneridge.get_config('enqueuer', 'password') try: res = requests.get(root + '/list_unhandled', auth=(username, password)) except: # For some reason, we sometimes get a requests failure here, even # though everything seems to be working fine. Ignore that, and try # again later. logging.exception('Error listing unhandled pushes') return try: queue = json.loads(res.text) except: # Yet another failure mode. Yay. logging.exception('Error demarshalling result %s' % (res.text,)) return for entry in queue: try: requests.post(root + '/mark_handled', data={'id': entry['pushid']}, auth=(username, password)) except: # If we fail to mark this as handled, wait until the next try so we # don't run the same thing more than once. It's not the end of the # world ot have to wait... logging.exception('Error marking entry %s as handled' % (entry,)) return logging.debug('Equeuing entry %s' % (entry,)) stoneridge.enqueue(nightly=False, ldap=entry['ldap'], sha=entry['sha'], netconfigs=entry['netconfigs'], operating_systems=entry['operating_systems'], srid=entry['srid'])