Skip to content

Commit

Permalink
Creates 'amplified_greet_guests' to demonstrate chaining for the prog…
Browse files Browse the repository at this point in the history
…ramming guide.
  • Loading branch information
Damir Jungic committed Jan 25, 2021
1 parent 8a284ae commit 02de166
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 17 additions & 0 deletions firexapp/tasks/example.py
Expand Up @@ -56,3 +56,20 @@ def greet_guests(self: FireXTask, guests):
@SingleArgDecorator('guests')
def to_list(guests):
return guests.split(',')


@app.task(returns=['amplified_message'])
def amplify(to_amplify):
return to_amplify.upper()


@app.task(bind=True, returns=['amplified_greeting'])
def amplified_greet_guests(self: FireXTask, guests):

# Create a chain that can be enqueued. The greet_guests service will produce a guests_greeting,
# which will then be delivered to amplify as its to_amplify argument.
amplified_greet_guests_chain = greet_guests.s(guests=guests) | amplify.s(to_amplify='@guests_greeting')

# Chains can be enqueued just like signatures. You can consider a signature a chain with only one service.
chain_results = self.enqueue_child_and_get_results(amplified_greet_guests_chain)
return chain_results['amplified_message']
21 changes: 20 additions & 1 deletion tests/integration_tests/example_flow_tests.py
Expand Up @@ -39,4 +39,23 @@ def assert_expected_firex_output(self, cmd_output, cmd_err):

logs_dir = get_log_dir_from_output(cmd_output)
completion_data = get_completion_report_data(logs_dir)
assert completion_data['results']['chain_results']['guests_greeting'] == "Hello John! Hello Mohammad!"
assert completion_data['results']['chain_results']['guests_greeting'] == "Hello John! Hello Mohammad!"


class AmplifiedGreetGuestsTest(FlowTestConfiguration):

def initial_firex_options(self) -> list:
return ['submit', '--chain', "amplified_greet_guests", "--guests", "John,Mohammad"]

def assert_expected_return_code(self, ret_value):
assert_is_good_run(ret_value)

def assert_expected_firex_output(self, cmd_output, cmd_err):
assert not cmd_err, "no errors expected"

logs_dir = get_log_dir_from_output(cmd_output)
completion_data = get_completion_report_data(logs_dir)
expected_result = "Hello John! Hello Mohammad!".upper()
actual_result = completion_data['results']['chain_results']['amplified_greeting']
assert actual_result == expected_result, \
"Expected '%s' \n Received '%s'" % (expected_result, actual_result)

0 comments on commit 02de166

Please sign in to comment.