Beispiel #1
0
def cancel_workflow():
    context = cancel_workflow.context
    workflow_id = context['workflow_id']
    run_id = context['run_id']
    domain_name = context['domain_name']
    workflow_execution = get_workflow_execution(domain_name, workflow_id, run_id)
    workflow_execution.request_cancel()
Beispiel #2
0
def cancel_workflow():
    context = cancel_workflow.context
    workflow_id = context["workflow_id"]
    run_id = context["run_id"]
    domain_name = context["domain_name"]
    workflow_execution = get_workflow_execution(domain_name, workflow_id,
                                                run_id)
    workflow_execution.request_cancel()
Beispiel #3
0
def cancel_workflow():
    context = cancel_workflow.context
    workflow_id = context['workflow_id']
    run_id = context['run_id']
    domain_name = context['domain_name']
    workflow_execution = get_workflow_execution(domain_name, workflow_id,
                                                run_id)
    workflow_execution.request_cancel()
Beispiel #4
0
def wait_and_signal(name='signal'):
    time.sleep(1 + len(name))  # Hoping to be deterministic
    context = wait_and_signal.context
    ex = get_workflow_execution(context['domain_name'], context['workflow_id'], context['run_id'])
    ex.connection.signal_workflow_execution(
        ex.domain.name,
        name,
        ex.workflow_id,
        run_id=ex.run_id,
    )
Beispiel #5
0
def wait_and_signal(name="signal"):
    time.sleep(1 + len(name))  # Hoping to be deterministic
    context = wait_and_signal.context
    ex = get_workflow_execution(context["domain_name"], context["workflow_id"],
                                context["run_id"])
    ex.connection.signal_workflow_execution(
        ex.domain.name,
        name,
        ex.workflow_id,
        run_id=ex.run_id,
    )
Beispiel #6
0
def send_unrequested_signal():
    context = send_unrequested_signal.context
    ex = get_workflow_execution(context['domain_name'], context['workflow_id'], context['run_id'])
    ex.connection.signal_workflow_execution(
        ex.domain.name,
        'unexpected',
        ex.workflow_id,
        input='Hi there!',  # not JSON-formatted
        run_id=ex.run_id,
    )
    return 'signal sent!'
Beispiel #7
0
def send_unrequested_signal():
    context = send_unrequested_signal.context
    ex = get_workflow_execution(context["domain_name"], context["workflow_id"],
                                context["run_id"])
    ex.connection.signal_workflow_execution(
        ex.domain.name,
        "unexpected",
        ex.workflow_id,
        input="Hi there!",  # not JSON-formatted
        run_id=ex.run_id,
    )
    return "signal sent!"
Beispiel #8
0
def send_unrequested_signal():
    context = send_unrequested_signal.context
    ex = get_workflow_execution(context['domain_name'], context['workflow_id'],
                                context['run_id'])
    ex.connection.signal_workflow_execution(
        ex.domain.name,
        'unexpected',
        ex.workflow_id,
        input='Hi there!',  # not JSON-formatted
        run_id=ex.run_id,
    )
    return 'signal sent!'
Beispiel #9
0
def standalone(
    context,
    workflow,
    domain,
    workflow_id,
    execution_timeout,
    tags,
    decision_tasks_timeout,
    input,
    input_file,
    nb_workers,
    nb_deciders,
    heartbeat,
    display_status,
    repair,
    force_activities,
):
    """
    This command spawn a decider and an activity worker to execute a workflow
    with a single main process.

    """
    disable_boto_connection_pooling()

    if force_activities and not repair:
        raise ValueError(
            "You should only use --force-activities with --repair.")

    workflow_class = get_workflow(workflow)
    if not workflow_id:
        workflow_id = workflow_class.name

    wf_input = {}
    if input or input_file:
        wf_input = get_or_load_input(input_file, input)

    if repair:
        repair_run_id = None
        if " " in repair:
            repair, repair_run_id = repair.split(" ", 1)
        # get the previous execution history, it will serve as "default history"
        # for activities that succeeded in the previous execution
        logger.info('retrieving history of previous execution: domain={} '
                    'workflow_id={} run_id={}'.format(domain, repair,
                                                      repair_run_id))
        workflow_execution = get_workflow_execution(domain,
                                                    repair,
                                                    run_id=repair_run_id)
        previous_history = History(workflow_execution.history())
        repair_run_id = workflow_execution.run_id
        previous_history.parse()
        # get the previous execution input if none passed
        if not input and not input_file:
            wf_input = previous_history.events[0].input
        if not tags:
            tags = workflow_execution.tag_list
    else:
        previous_history = None
        repair_run_id = None
        if not tags:
            get_tag_list = getattr(workflow_class, 'get_tag_list', None)
            if get_tag_list:
                tags = get_tag_list(workflow_class, *wf_input.get('args', ()),
                                    **wf_input.get('kwargs', {}))
            else:
                tags = getattr(workflow_class, 'tag_list', None)
            if tags == Workflow.INHERIT_TAG_LIST:
                tags = None

    task_list = create_unique_task_list(workflow_id)
    logger.info('using task list {}'.format(task_list))
    decider_proc = multiprocessing.Process(
        target=decider.command.start,
        args=(
            [workflow],
            domain,
            task_list,
        ),
        kwargs={
            'nb_processes': nb_deciders,
            'repair_with': previous_history,
            'force_activities': force_activities,
            'is_standalone': True,
            'repair_workflow_id': repair or None,
            'repair_run_id': repair_run_id,
        },
    )
    decider_proc.start()

    worker_proc = multiprocessing.Process(
        target=worker.command.start,
        args=(
            domain,
            task_list,
        ),
        kwargs={
            'nb_processes': nb_workers,
            'heartbeat': heartbeat,
        },
    )
    worker_proc.start()

    print('starting workflow {}'.format(workflow), file=sys.stderr)
    ex = start_workflow.callback(
        workflow,
        domain,
        workflow_id,
        task_list,
        execution_timeout,
        tags,
        decision_tasks_timeout,
        format.input(wf_input),
        None,
        local=False,
    )
    while True:
        time.sleep(2)
        ex = helpers.get_workflow_execution(
            domain,
            ex.workflow_id,
            ex.run_id,
        )
        if display_status:
            print('status: {}'.format(ex.status), file=sys.stderr)
        if ex.status == ex.STATUS_CLOSED:
            print('execution {} finished'.format(ex.workflow_id),
                  file=sys.stderr)
            break

    os.kill(worker_proc.pid, signal.SIGTERM)
    worker_proc.join()
    os.kill(decider_proc.pid, signal.SIGTERM)
    decider_proc.join()
Beispiel #10
0
def standalone(context,
               workflow,
               domain,
               workflow_id,
               execution_timeout,
               tags,
               decision_tasks_timeout,
               input,
               input_file,
               nb_workers,
               nb_deciders,
               heartbeat,
               display_status,
               repair,
               force_activities,
               ):
    """
    This command spawn a decider and an activity worker to execute a workflow
    with a single main process.

    """
    disable_boto_connection_pooling()

    if force_activities and not repair:
        raise ValueError(
            "You should only use --force-activities with --repair."
        )

    workflow_class = get_workflow(workflow)
    if not workflow_id:
        workflow_id = workflow_class.name

    wf_input = {}
    if input or input_file:
        wf_input = get_or_load_input(input_file, input)

    if repair:
        repair_run_id = None
        if " " in repair:
            repair, repair_run_id = repair.split(" ", 1)
        # get the previous execution history, it will serve as "default history"
        # for activities that succeeded in the previous execution
        logger.info(
            'retrieving history of previous execution: domain={} '
            'workflow_id={} run_id={}'.format(domain, repair, repair_run_id)
        )
        workflow_execution = get_workflow_execution(domain, repair, run_id=repair_run_id)
        previous_history = History(workflow_execution.history())
        repair_run_id = workflow_execution.run_id
        previous_history.parse()
        # get the previous execution input if none passed
        if not input and not input_file:
            wf_input = previous_history.events[0].input
        if not tags:
            tags = workflow_execution.tag_list
    else:
        previous_history = None
        repair_run_id = None
        if not tags:
            get_tag_list = getattr(workflow_class, 'get_tag_list', None)
            if get_tag_list:
                tags = get_tag_list(workflow_class, *wf_input.get('args', ()), **wf_input.get('kwargs', {}))
            else:
                tags = getattr(workflow_class, 'tag_list', None)
            if tags == Workflow.INHERIT_TAG_LIST:
                tags = None

    task_list = create_unique_task_list(workflow_id)
    logger.info('using task list {}'.format(task_list))
    decider_proc = multiprocessing.Process(
        target=decider.command.start,
        args=(
            [workflow],
            domain,
            task_list,
        ),
        kwargs={
            'nb_processes': nb_deciders,
            'repair_with': previous_history,
            'force_activities': force_activities,
            'is_standalone': True,
            'repair_workflow_id': repair or None,
            'repair_run_id': repair_run_id,
        },
    )
    decider_proc.start()

    worker_proc = multiprocessing.Process(
        target=worker.command.start,
        args=(
            domain,
            task_list,
        ),
        kwargs={
            'nb_processes': nb_workers,
            'heartbeat': heartbeat,
        },
    )
    worker_proc.start()

    print('starting workflow {}'.format(workflow), file=sys.stderr)
    ex = start_workflow.callback(
        workflow,
        domain,
        workflow_id,
        task_list,
        execution_timeout,
        tags,
        decision_tasks_timeout,
        format.input(wf_input),
        None,
        local=False,
    )
    while True:
        time.sleep(2)
        ex = helpers.get_workflow_execution(
            domain,
            ex.workflow_id,
            ex.run_id,
        )
        if display_status:
            print('status: {}'.format(ex.status), file=sys.stderr)
        if ex.status == ex.STATUS_CLOSED:
            print('execution {} finished'.format(ex.workflow_id), file=sys.stderr)
            break

    os.kill(worker_proc.pid, signal.SIGTERM)
    worker_proc.join()
    os.kill(decider_proc.pid, signal.SIGTERM)
    decider_proc.join()