Пример #1
0
    def test_gets_event(self):
        queue = Queue(capacity=10)
        event = QueueEvent('test')
        queue.puts((event, 1, 2, 3, event))
        result = queue.gets(count=5, timeout=TIMEOUT)
        self.assertEqual(result, (event, ))
        result = queue.gets(count=5, timeout=TIMEOUT)
        self.assertEqual(result, (1, 2, 3, event))

        task = PeriodicTask(TIMEOUT / 10, lambda: queue.put(1))
        task.start()
        try:
            result = queue.gets(count=5, timeout=TIMEOUT)
            self.assertEqual(result, (1, 1, 1, 1, 1))
        finally:
            task.cancel()
            task.join()
Пример #2
0
    def test_flush_timeout(self):
        queue = Queue(capacity=10)
        self.assertEqual(queue.flush(timeout=TIMEOUT), 0)
        queue.put('test', timeout=TIMEOUT)
        self.assertIsNone(queue.flush(timeout=TIMEOUT))
        queue.puts(range(100), timeout=TIMEOUT)
        self.assertIsNone(queue.flush(timeout=TIMEOUT))

        def proc():
            for item in queue.gets(count=1, timeout=TIMEOUT):
                if isinstance(item, QueueEvent):
                    item.set()

        task = PeriodicTask(TIMEOUT / 10, proc)
        task.start()
        try:
            self.assertIsNotNone(queue.flush())
        finally:
            task.cancel()
            task.join()
Пример #3
0
 def __init__(
         self,
         path,
         max_size=100 * 1024 * 1024,  # 100MB
         maintenance_period=60,  # 1 minute
         retention_period=7 * 24 * 60 * 60,  # 7 days
         write_timeout=60,  # 1 minute
 ):
     self.path = os.path.abspath(path)
     self.max_size = max_size
     self.maintenance_period = maintenance_period
     self.retention_period = retention_period
     self.write_timeout = write_timeout
     self._maintenance_routine(silent=False)
     self._maintenance_task = PeriodicTask(
         interval=self.maintenance_period,
         function=self._maintenance_routine,
         kwargs={'silent': True},
     )
     self._maintenance_task.daemon = True
     self._maintenance_task.start()
 def __init__(
         self,
         path,
         max_size=50 * 1024 * 1024,  # 50MiB
         maintenance_period=60,  # 1 minute
         retention_period=7 * 24 * 60 * 60,  # 7 days
         write_timeout=60,  # 1 minute
 ):
     self.path = os.path.abspath(path)
     self.max_size = max_size
     self.maintenance_period = maintenance_period
     self.retention_period = retention_period
     self.write_timeout = write_timeout
     # Run maintenance routine once upon instantiating
     self._maintenance_routine()
     self._maintenance_task = PeriodicTask(
         interval=self.maintenance_period,
         function=self._maintenance_routine,
     )
     self._maintenance_task.daemon = True
     self._maintenance_task.start()
Пример #5
0
 def __init__(self, **options):
     self.options = Options(**options)
     if not self.options.instrumentation_key:
         raise ValueError('The instrumentation_key is not provided.')
     self.storage = LocalFileStorage(
         path=self.options.storage_path,
         max_size=self.options.storage_max_size,
         maintenance_period=self.options.storage_maintenance_period,
         retention_period=self.options.storage_retention_period,
     )
     self.transport = AsyncTransport(
         self,
         max_batch_size=100,
         wait_period=self.options.export_interval,
     )
     self._transmission_task = PeriodicTask(
         interval=self.options.storage_maintenance_period,
         function=self._transmission_routine,
     )
     self._transmission_task.daemon = True
     self._transmission_task.start()