Exemplo n.º 1
0
 def _deserialize_handler(cls, data):
     if not data:
         return None
     elif 'path' in data:
         func = get_func(data.pop('path'))
         if isinstance(func, types.FunctionType):
             return func
         return func(**data)
     else:
         raise exceptions.NonRecoverableError(
             'Cannot deserialize: {0!r}'.format(data))
Exemplo n.º 2
0
    def _get_operation_class(self, task_type):
        if task_type in self._op_types_cache:
            return self._op_types_cache[task_type]
        if task_type == 'SubgraphTask':
            op_cls = SubgraphTask
        elif '.' in task_type:
            op_cls = get_func(task_type)
        else:
            op_cls = getattr(tasks, task_type)

        if not issubclass(op_cls, tasks.WorkflowTask):
            raise RuntimeError(
                '{0} is not a subclass of WorkflowTask'.format(task_type))
        self._op_types_cache[task_type] = op_cls
        return op_cls
Exemplo n.º 3
0
    def handle_task(self, full_task):
        event_type = full_task['event_type']
        hook = self._get_hook(event_type)
        if not hook:
            return
        logger.info('The hook consumer received `{0}` event and the hook '
                    'implementation is: `{1}`'.format(
                        event_type, hook.get('implementation')))

        try:
            kwargs = hook.get('inputs') or {}
            context = full_task['context']
            context['event_type'] = event_type
            context['timestamp'] = full_task['timestamp']
            context['arguments'] = full_task['message']['arguments']
            hook_function = get_func(hook['implementation'])
            result = hook_function(context, **kwargs)
            result = {'ok': True, 'result': result}
        except Exception as e:
            result = {'ok': False, 'error': e.message}
            logger.error('{0!r}, while running the hook triggered by the '
                         'event: {1}'.format(e, event_type))
        return result
Exemplo n.º 4
0
 def get_func(self):
     task_name = self.cloudify_context['task_name']
     return utils.get_func(task_name)