From 02de1664bdedbccfb5c2a81770ed57eb0c9094a5 Mon Sep 17 00:00:00 2001 From: Damir Jungic Date: Mon, 25 Jan 2021 03:25:58 -0800 Subject: [PATCH] Creates 'amplified_greet_guests' to demonstrate chaining for the programming guide. --- firexapp/tasks/example.py | 17 +++++++++++++++ tests/integration_tests/example_flow_tests.py | 21 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/firexapp/tasks/example.py b/firexapp/tasks/example.py index fe37059..95992c2 100644 --- a/firexapp/tasks/example.py +++ b/firexapp/tasks/example.py @@ -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'] diff --git a/tests/integration_tests/example_flow_tests.py b/tests/integration_tests/example_flow_tests.py index f35e13a..c6097ff 100644 --- a/tests/integration_tests/example_flow_tests.py +++ b/tests/integration_tests/example_flow_tests.py @@ -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!" \ No newline at end of file + 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)