Exemplo n.º 1
0
def test_aynchronous_tasks(monkeypatch):
    """Test asynchronous tasks.
    """

    monkeypatch.setattr(activity.Activity, '__init__', lambda self: None)
    monkeypatch.setattr(activity.Activity, 'heartbeat', lambda self: None)

    tasks = [MagicMock() for i in range(5)]
    tasks[2].return_value = dict(oi='mondo')
    tasks[4].return_value = dict(bonjour='monde')
    expected_response = dict(
        list(tasks[2].return_value.items()) +
        list(tasks[4].return_value.items()))

    workers = 2
    current_runner = runner.Async(*tasks, max_workers=workers)

    assert current_runner.max_workers == workers
    assert len(current_runner.tasks) == len(tasks)

    current_activity = activity.Activity()
    current_activity.hydrate(dict(runner=current_runner))

    context = dict(hello='world')
    resp = current_runner.execute(current_activity, context)

    for current_task in tasks:
        assert current_task.called

    assert resp == expected_response
Exemplo n.º 2
0
def test_aynchronous_tasks(monkeypatch, boto_client):
    """Test asynchronous tasks.
    """

    monkeypatch.setattr(activity.ActivityExecution, 'heartbeat',
        lambda self: None)

    tasks = [MagicMock() for i in range(5)]
    tasks[2].return_value = dict(oi='mondo')
    tasks[4].return_value = dict(bonjour='monde')
    expected_response = dict(
        list(tasks[2].return_value.items()) +
        list(tasks[4].return_value.items()))

    workers = 2
    current_runner = runner.Async(*tasks, max_workers=workers)

    assert current_runner.max_workers == workers
    assert len(current_runner.tasks) == len(tasks)

    current_activity = activity.ActivityExecution(boto_client,
         'activityId', 'taskToken', '{"hello": "world"}')

    resp = current_runner.execute(current_activity, current_activity.context)

    for current_task in tasks:
        assert current_task.called

    assert resp == expected_response
Exemplo n.º 3
0
 def hello_world_five_activity(self):
     return self.create(
         name='hello_world_five',
         tasks=runner.Async(
             tasks.print_hello_task.fill(
                 namespace='activity_five_task_one',
                 workflow_id='execution.workflow_id',
                 sleep=param.StaticParam(10),
                 activity_name=param.StaticParam('Activity 5'),
                 task_name=param.StaticParam('Task 1')),
             tasks.print_hello_task.fill(
                 namespace='activity_five_task_two',
                 workflow_id='execution.workflow_id',
                 activity_name=param.StaticParam('Activity 5'),
                 task_name=param.StaticParam('Task 2'))))
Exemplo n.º 4
0
from garcon import activity
from garcon import runner

domain = 'dev'
name = 'workflow_name'
create = activity.create(domain, name)

activity_1 = create(
    name='activity_1',
    tasks=runner.Sync(lambda activity, context: print('activity_1')))

activity_2 = create(name='activity_2',
                    requires=[activity_1],
                    tasks=runner.Async(
                        lambda activity, context: print('activity_2_task_1'),
                        lambda activity, context: print('activity_2_task_2')))

activity_3 = create(
    name='activity_3',
    requires=[activity_1],
    tasks=runner.Sync(lambda activity, context: print('activity_3')))

activity_4 = create(
    name='activity_4',
    requires=[activity_3, activity_2],
    tasks=runner.Sync(lambda activity, context: print('activity_4')))


def on_exception(actor, exception):
    """Handler for exceptions.
Exemplo n.º 5
0
def activity_failure(context, activity):
    num = int(random.random() * 4)
    if num != 3:
        logger.warn('activity_3: fails')
        raise Exception('fails')

    print('activity_3: end')


test_activity_1 = create(
    name='activity_1',
    run=runner.Sync(lambda context, activity: logger.debug('activity_1')))

test_activity_2 = create(
    name='activity_2',
    requires=[test_activity_1],
    run=runner.Async(
        lambda context, activity: logger.debug('activity_2_task_1'),
        lambda context, activity: logger.debug('activity_2_task_2')))

test_activity_3 = create(name='activity_3',
                         retry=10,
                         requires=[test_activity_1],
                         run=runner.Sync(activity_failure))

test_activity_4 = create(
    name='activity_4',
    requires=[test_activity_3, test_activity_2],
    run=runner.Sync(lambda context, activity: logger.debug('activity_4')))