Skip to content

Commit ba4253d

Browse files
committed
(maint) Return exitcode and stderr in task response
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.
1 parent 6fbf616 commit ba4253d

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/src/modules/task.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Task::Task(const fs::path& exec_prefix,
120120
actions.push_back(TASK_RUN_ACTION);
121121

122122
PCPClient::Schema input_schema { TASK_RUN_ACTION, lth_jc::JsonContainer { TASK_RUN_ACTION_INPUT_SCHEMA } };
123-
PCPClient::Schema output_schema { TASK_RUN_ACTION, PCPClient::TypeConstraint::String };
123+
PCPClient::Schema output_schema { TASK_RUN_ACTION };
124124

125125
input_validator_.registerSchema(input_schema);
126126
results_validator_.registerSchema(output_schema);
@@ -512,10 +512,16 @@ void Task::processOutputAndUpdateMetadata(ActionResponse& response)
512512
if (isValidUTF8(output)) {
513513
// Use a temporary object to create a JSON string. The JsonContainer API doesn't
514514
// provide a way to set the root to a string unless that string is already quoted.
515-
lth_jc::JsonContainer stdout_result;
516-
stdout_result.set("_output", output);
515+
lth_jc::JsonContainer result;
516+
result.set("exitcode", response.output.exitcode);
517+
if (!output.empty()) {
518+
result.set("stdout", output);
519+
}
520+
if (!response.output.std_err.empty()) {
521+
result.set("stderr", response.output.std_err);
522+
}
517523

518-
response.setValidResultsAndEnd(stdout_result.get<lth_jc::JsonContainer>("_output"));
524+
response.setValidResultsAndEnd(std::move(result));
519525
} else {
520526
LOG_DEBUG("Obtained invalid UTF-8 on stdout for the {1}; stdout:\n{2}",
521527
response.prettyRequestLabel(), output);

lib/tests/unit/modules/task_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ TEST_CASE("Modules::Task::executeAction", "[modules][output]") {
186186
0 };
187187
ActionRequest request { RequestType::Blocking, echo_content };
188188

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

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

242-
auto output = response.action_metadata.get<std::string>("results");
242+
auto output = response.action_metadata.get<std::string>({"results", "stdout"});
243243
boost::trim(output);
244244
REQUIRE(output == "hello");
245245
REQUIRE(response.action_metadata.get<bool>("results_are_valid"));

0 commit comments

Comments
 (0)