Exemple #1
0
 def test_context(self):
     assert not hasattr(g, 'task')
     assert not hasattr(g, 'message')
     with g.set_context(task=1, message=2):
         self.assertEqual(g.task, 1)
         self.assertEqual(g.message, 2)
     assert not hasattr(g, 'task')
     assert not hasattr(g, 'message')
Exemple #2
0
def handle_task(request):
    env = request.environ
    task = env.get('chapmand.task')
    msg = env.get('chapmand.message')
    if task is None or msg is None:
        raise exc.HTTPNotFound()
    with g.set_context(request=request, registry=request.registry):
        task.handle(msg)
    return exc.HTTPOk()
Exemple #3
0
 def handle(self, msg):
     while msg:
         with g.set_context(task=self, message=msg):
             if self._state.status in ("success", "failure"):
                 log.warning("Ignoring message to %s task: %r", self._state.status, msg)
             else:
                 method = getattr(self, msg.slot)
                 method(msg)
             msg.retire()
             msg = None
Exemple #4
0
 def handle(self, msg):
     while msg:
         with g.set_context(task=self, message=msg):
             if self._state.status in ('success', 'failure'):
                 log.warning('Ignoring message to %s task: %r',
                             self._state.status, msg)
             else:
                 method = getattr(self, msg.slot)
                 method(msg)
             msg.retire()
             msg = None