Пример #1
0
    def _delete(cls, data):
        task_id = cls.get_task_id(data)
        future = asyncio.Future()

        def callback(signal, data, taskid=None):
            if taskid == task_id:
                future.set_result(data)
        dispatcher.register(callback, signal=cls.DELETED_SIGNAL)
        dispatcher.send(cls.DELETE_SIGNAL, data, taskid=task_id)

        result = yield from future
        return result
Пример #2
0
    def _get(cls, data):
        task_id = cls.get_task_id(data)
        fut = asyncio.Future()

        def callback(signal, data, taskid=None):
            if taskid == task_id:
                fut.set_result(data)

        dispatcher.register(callback, signal=cls.GOT_SIGNAL)
        dispatcher.send(cls.GET_SIGNAL, data, taskid=task_id)

        result = yield from fut
        return fut.result()
Пример #3
0
 def do_delete(cls, signal, data, taskid=None):
     logger.debug(
         '{} DELETE: {} {} {}'.format(
             cls.__name__, signal, data, taskid)
     )
     result = cls.delete(**(data or {}))
     logger.debug(
         '{} DELETED: {}'.format(
             cls.__name__, result)
     )
     dispatcher.send(
         signal=cls.DELETED_SIGNAL,
         data=result,
         taskid=taskid)
Пример #4
0
 def do_get(cls, signal, data, taskid=None):
     logger.debug(
         '{} GET: {} {} {}'.format(
             cls.__name__, signal, data, taskid)
     )
     result = cls.get(**(data or {}))
     logger.debug(
         '{} GOT: {}'.format(
             cls.__name__, result)
     )
     dispatcher.send(
         signal=cls.GOT_SIGNAL,
         data=result,
         taskid=taskid)
Пример #5
0
 def do_create_or_update(cls, signal, data, taskid=None):
     logger.debug('{} CREATE_OR_UPDATE: {} {} {}'.format(
         cls.__name__, signal, data, taskid))
     result, action = cls.create_or_update(**(data or {}))
     if action == 'create':
         action_verb = 'CREATED'
         resp_signal = cls.CREATED_SIGNAL
     elif action == 'update':
         action_verb = 'UPDATED'
         resp_signal = cls.UPDATED_SIGNAL
     else:
         action_verb = 'CREATE_OR_UPDATE_FAILED'
         resp_signal = cls.CREATE_OR_UPDATE_ERROR
     logger.debug('{} {}: {}'.format(cls.__name__, action_verb, result))
     dispatcher.send(signal=resp_signal, data=result, taskid=taskid)
Пример #6
0
 def do_create_or_update(cls, signal, data, taskid=None):
     logger.debug(
         '{} CREATE_OR_UPDATE: {} {} {}'.format(
             cls.__name__, signal, data, taskid)
     )
     result, action = cls.create_or_update(**(data or {}))
     if action == 'create':
         action_verb = 'CREATED'
         resp_signal = cls.CREATED_SIGNAL
     elif action == 'update':
         action_verb = 'UPDATED'
         resp_signal = cls.UPDATED_SIGNAL
     else:
         action_verb = 'CREATE_OR_UPDATE_FAILED'
         resp_signal = cls.CREATE_OR_UPDATE_ERROR
     logger.debug(
         '{} {}: {}'.format(
             cls.__name__, action_verb, result)
     )
     dispatcher.send(
         signal=resp_signal,
         data=result,
         taskid=taskid)
Пример #7
0
 def do_delete(cls, signal, data, taskid=None):
     logger.debug('{} DELETE: {} {} {}'.format(cls.__name__, signal, data,
                                               taskid))
     result = cls.delete(**(data or {}))
     logger.debug('{} DELETED: {}'.format(cls.__name__, result))
     dispatcher.send(signal=cls.DELETED_SIGNAL, data=result, taskid=taskid)
Пример #8
0
 def do_get(cls, signal, data, taskid=None):
     logger.debug('{} GET: {} {} {}'.format(cls.__name__, signal, data,
                                            taskid))
     result = cls.get(**(data or {}))
     logger.debug('{} GOT: {}'.format(cls.__name__, result))
     dispatcher.send(signal=cls.GOT_SIGNAL, data=result, taskid=taskid)
Пример #9
0
        dispatcher.send(cls.GET_SIGNAL, data, taskid=task_id)

        result = yield from fut
        return fut.result()

    @classmethod
    def _create(cls, data, async=False):
        task_id = cls.get_task_id(data)
        fut = asyncio.Future()

        def callback(signal, data, taskid=None):
            if taskid == task_id:
                fut.set_result(data)

        dispatcher.register(callback, signal=cls.CREATED_SIGNAL)
        dispatcher.send(cls.CREATE_SIGNAL, data, taskid=task_id)

        result = yield from fut
        return fut.result()

    @classmethod
    def _update(cls, data):
        task_id = cls.get_task_id(data)
        future = asyncio.Future()

        def callback(signal, data, taskid=None):
            if taskid == task_id:
                future.set_result(data)
        dispatcher.register(callback, signal=cls.UPDATED_SIGNAL)
        dispatcher.send(cls.UPDATE_SIGNAL, data, taskid=task_id)