Exemplo n.º 1
0
    def _runloop(self):
        while not self.service._stop:
            try:
                item = self.queue.get(timeout=1.0)
                if item is self._shutdown_sentinel:
                    self.queue.put(item)
                    break
            except queue.Empty:
                continue

            # Create an ExecuteContext if we didn't have one
            if isinstance(item, ExecuteContext):
                context = item
                item = context.item
                context.raw_wrapped = False
            else:
                context = ExecuteContext(item=item)
                context.raw_wrapped = True

            try:
                context.start()
                result = self.execute(item, context)
                self.work_success(context, result)
            except TryLater:
                self.work_retry(context)
            except Exception as ex:
                self.work_fail(context, ex)

            finally:
                self.queue.task_done()
Exemplo n.º 2
0
    def _runloop(self):
        while not self.service._stop:
            try:
                item = self.queue.get(timeout=1.0)
                if item is self._shutdown_sentinel:
                    self.queue.put(item)
                    break
            except queue.Empty:
                continue

            # Create an ExecuteContext if we didn't have one
            if isinstance(item, ExecuteContext):
                context = item
                item = context.item
                context.raw_wrapped = False
            else:
                context = ExecuteContext(item=item)
                context.raw_wrapped = True

            try:
                context.start()
                result = self.execute(item, context)
                self.work_success(context, result)
            except TryLater:
                self.work_retry(context)
            except Exception as ex:
                self.work_fail(context, ex)

            finally:
                self.queue.task_done()
Exemplo n.º 3
0
    def _runloop(self):
        while not self.service._stop:
            try:
                item = self.queue.get(timeout=1.0)
                if item is self._shutdown_sentinel:
                    self.queue.put(item)
                    break
            except queue.Empty:
                continue

            if isinstance(item, ExecuteContext):
                context = item
                item = context.item
            else:
                context = ExecuteContext(item=item)
            try:
                result = self.execute(item, context)
                if context.deferred is not None:
                    context.deferred.callback(result)
            except TryLater:
                context.attempt += 1
                self.queue.put(context)
            except Exception as ex:
                if context.deferred is not None:
                    self.unhandled = None
                    context.deferred.addErrback(self.unhandledErrback)
                    context.deferred.errback(ex)
                    if self.unhandled is not None:
                        self.unhandled.raiseException()
                else:
                    raise
            finally:
                self.queue.task_done()
Exemplo n.º 4
0
    def _runloop(self):
        while not self.service._stop:
            try:
                item = self.queue.get(timeout=1.0)
                if item is self._shutdown_sentinel:
                    self.queue.put(item)
                    break
            except queue.Empty:
                continue

            # Create an ExecuteContext if we didn't have one
            if isinstance(item, ExecuteContext):
                context = item
                item = context.item
            else:
                context = ExecuteContext(item=item)

            try:
                context.start()
                result = self.execute(item, context)
                self.n_completed.increment()
                self.execute_duration_ms.add(context.elapsed * 1000.0)
                context.set_result(result)
            except TryLater:
                self.n_trylater.increment()
                context.attempt += 1
                self.queue.put(context)
            except Exception as ex:
                self.n_unhandled.increment()
                self.execute_duration_ms.add(context.elapsed * 1000.0)
                handled = context.set_exception(ex)
                if not handled:
                    raise

            finally:
                self.queue.task_done()
Exemplo n.º 5
0
 def test_comparisons(self):
     self.assertEqual(ExecuteContext(), ExecuteContext())
     self.assertEqual(ExecuteContext(item=10), ExecuteContext(item=10))
     self.assertNotEqual(ExecuteContext(), ExecuteContext(item=4))
     self.assertNotEqual(ExecuteContext(item=3), ExecuteContext(item=4))
     self.assertLess(ExecuteContext(item=0), ExecuteContext(item=10))
     self.assertGreater(ExecuteContext(item=10), ExecuteContext(item=0))
Exemplo n.º 6
0
 def makeContext(self, item):
     """Helper for making an ExecuteContext with a default future"""
     return ExecuteContext(item=item, future=futures.Future())
Exemplo n.º 7
0
    def makeContext(self, item):
        d = Deferred()
        d.addErrback(self.handle_error)

        ctx = ExecuteContext(item=item, deferred=d)
        return ctx
Exemplo n.º 8
0
    def makeContext(self, item):
        d = Deferred()
        d.addCallback(self.saw_item)

        ctx = ExecuteContext(item=item, deferred=d)
        return ctx
Exemplo n.º 9
0
 def submit(self, item):
     """Enqueue `item` into this task's Queue.  Returns a `Future`"""
     future = Future()
     work = ExecuteContext(item=item, future=future)
     self.queue.put(work)
     return future