Skip to content

Commit

Permalink
(maint) Return exitcode and stderr in task response
Browse files Browse the repository at this point in the history
In the task response, return exitcode and stderr as well as stdout. This
allows a consumer to skip querying status, as all the data they need for
a task is in the response.
  • Loading branch information
MikaelSmith committed Aug 28, 2017
1 parent 6fbf616 commit ba4253d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions lib/src/modules/task.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Task::Task(const fs::path& exec_prefix,
actions.push_back(TASK_RUN_ACTION);

PCPClient::Schema input_schema { TASK_RUN_ACTION, lth_jc::JsonContainer { TASK_RUN_ACTION_INPUT_SCHEMA } };
PCPClient::Schema output_schema { TASK_RUN_ACTION, PCPClient::TypeConstraint::String };
PCPClient::Schema output_schema { TASK_RUN_ACTION };

input_validator_.registerSchema(input_schema);
results_validator_.registerSchema(output_schema);
Expand Down Expand Up @@ -512,10 +512,16 @@ void Task::processOutputAndUpdateMetadata(ActionResponse& response)
if (isValidUTF8(output)) {
// Use a temporary object to create a JSON string. The JsonContainer API doesn't
// provide a way to set the root to a string unless that string is already quoted.
lth_jc::JsonContainer stdout_result;
stdout_result.set("_output", output);
lth_jc::JsonContainer result;
result.set("exitcode", response.output.exitcode);
if (!output.empty()) {
result.set("stdout", output);
}
if (!response.output.std_err.empty()) {
result.set("stderr", response.output.std_err);
}

response.setValidResultsAndEnd(stdout_result.get<lth_jc::JsonContainer>("_output"));
response.setValidResultsAndEnd(std::move(result));
} else {
LOG_DEBUG("Obtained invalid UTF-8 on stdout for the {1}; stdout:\n{2}",
response.prettyRequestLabel(), output);
Expand Down
6 changes: 3 additions & 3 deletions lib/tests/unit/modules/task_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ TEST_CASE("Modules::Task::executeAction", "[modules][output]") {
0 };
ActionRequest request { RequestType::Blocking, echo_content };

auto output = e_m.executeAction(request).action_metadata.get<std::string>("results");
auto output = e_m.executeAction(request).action_metadata.get<std::string>({"results", "stdout"});
boost::trim(output);
REQUIRE(output == "{\"message\":\"hello\"}");
}
Expand All @@ -212,7 +212,7 @@ TEST_CASE("Modules::Task::executeAction", "[modules][output]") {
0 };
ActionRequest request { RequestType::Blocking, echo_content };

auto output = e_m.executeAction(request).action_metadata.get<std::string>("results");
auto output = e_m.executeAction(request).action_metadata.get<std::string>({"results", "stdout"});
boost::trim(output);
REQUIRE(output == "hello");
}
Expand All @@ -239,7 +239,7 @@ TEST_CASE("Modules::Task::executeAction", "[modules][output]") {
ActionRequest request { RequestType::Blocking, echo_content };
auto response = e_m.executeAction(request);

auto output = response.action_metadata.get<std::string>("results");
auto output = response.action_metadata.get<std::string>({"results", "stdout"});
boost::trim(output);
REQUIRE(output == "hello");
REQUIRE(response.action_metadata.get<bool>("results_are_valid"));
Expand Down

0 comments on commit ba4253d

Please sign in to comment.