Ejemplo n.º 1
0
    def worker_webhook(tosend, url):
        interval = config.getfloat('cloud_verifier', 'retry_interval')
        exponential_backoff = config.getboolean('cloud_verifier',
                                                'exponential_backoff')
        session = requests.session()
        logger.info("Sending revocation event via webhook...")
        for i in range(config.getint('cloud_verifier', 'max_retries')):
            next_retry = retry.retry_time(exponential_backoff, interval, i,
                                          logger)
            try:
                response = session.post(url, json=tosend, timeout=5)
                if response.status_code in [200, 202]:
                    break

                logger.debug(
                    "Unable to publish revocation message %d times via webhook, "
                    "trying again in %d seconds. "
                    "Server returned status code: %s", i, next_retry,
                    response.status_code)
            except requests.exceptions.RequestException as e:
                logger.debug(
                    "Unable to publish revocation message %d times via webhook, "
                    "trying again in %d seconds: %s", i, next_retry, e)

            time.sleep(next_retry)
Ejemplo n.º 2
0
 def worker(tosend):
     context = zmq.Context()
     mysock = context.socket(zmq.PUB)
     mysock.connect(f"ipc://{_SOCKET_PATH}")
     # wait 100ms for connect to happen
     time.sleep(0.2)
     # now send it out via 0mq
     logger.info("Sending revocation event to listening nodes...")
     for i in range(config.getint('cloud_verifier', 'max_retries')):
         try:
             mysock.send_string(json.dumps(tosend))
             break
         except Exception as e:
             interval = config.getfloat('cloud_verifier', 'retry_interval')
             exponential_backoff = config.getboolean(
                 'cloud_verifier', 'exponential_backoff')
             next_retry = retry.retry_time(exponential_backoff, interval, i,
                                           logger)
             logger.debug(
                 "Unable to publish revocation message %d times, trying again in %f seconds: %s",
                 i, next_retry, e)
             time.sleep(next_retry)
     mysock.close()
Ejemplo n.º 3
0
 def test_exponential(self):
     b0 = rand_base_proper()
     b1 = random.random()
     n = rand_ntries()
     self.assertEqual(retry.retry_time(True, b0, n, None), b0**n)
     self.assertEqual(retry.retry_time(True, b1, n, None), abs(b1))
Ejemplo n.º 4
0
 def test_linear(self):
     b = rand_base()
     self.assertEqual(retry.retry_time(False, b, rand_ntries, None), abs(b))
Ejemplo n.º 5
0
 def test_general(self):
     self.assertTrue(
         retry.retry_time(rand_exp(), rand_base(), rand_ntries(), None) >= 0
     )