Exemplo n.º 1
0
    def test_signaling_task(self):
        SignalingTask = task_manager.get_signaling_task_class(task_manager.Task)

        st = SignalingTask()

        attr_results = {}
        @st.on_set.connect
        def on_set(sender, **kwargs):
            attr_results[kwargs.get('attr')] = kwargs.get('value')

        for prop in st._task_properties:
            setattr(st, prop, "%s_test" % prop)
            assert attr_results[prop] == getattr(st, prop)
Exemplo n.º 2
0
        task_definition = json.loads(task_json)
    except Exception as e:
        logger.exception("Unable to read task definition from stdin.")
        raise e

    # Load the task
    try:
        task_config = task_definition['config']['task']
        class_parts = task_config['class'].split('.')
        module_name = '.'.join(class_parts[:-1])
        class_name = class_parts[-1]
        module = importlib.import_module(module_name)
        TaskClass = getattr(module, class_name)

        # Instrument the task class to send signals.
        SignalingTaskClass = task_manager.get_signaling_task_class(TaskClass)

        task_args = task_config.get('args', [])
        task_kwargs = task_config.get('kwargs', {})
        task_kwargs['logger'] = logger
        task = SignalingTaskClass(*task_args, **task_kwargs)
    except:
        logger.exception("Unable to create task.")
        raise

    # Create the runner.
    post_url = task_definition['config']['update_url']
    task_runner = PostingTaskRunner(post_url=post_url, delay=1)

    # If running from tty, use same stdout/stderr.
    if sys.stdin.isatty():