@@ -36,15 +36,14 @@ grpc::Status CraneCtldServiceImpl::SubmitBatchTask(
36
36
37
37
auto result = m_ctld_server_->SubmitTaskToScheduler (std::move (task));
38
38
if (result.has_value ()) {
39
- task_id_t id = result.value ().get ();
40
- if (id != 0 ) {
39
+ auto submit_result = result.value ().get ();
40
+ if (submit_result. has_value () ) {
41
41
response->set_ok (true );
42
+ task_id_t id = submit_result.value ();
42
43
response->set_task_id (id);
43
44
} else {
44
45
response->set_ok (false );
45
- response->set_reason (
46
- " System error occurred or "
47
- " the number of pending tasks exceeded maximum value." );
46
+ response->set_reason (std::string (CraneErrStr (submit_result.error ())));
48
47
}
49
48
} else {
50
49
response->set_ok (false );
@@ -58,7 +57,9 @@ grpc::Status CraneCtldServiceImpl::SubmitBatchTasks(
58
57
grpc::ServerContext *context,
59
58
const crane::grpc::SubmitBatchTasksRequest *request,
60
59
crane::grpc::SubmitBatchTasksReply *response) {
61
- std::vector<result::result<std::future<task_id_t >, std::string>> results;
60
+ std::vector<result::result<std::future<result::result<task_id_t , CraneErr>>,
61
+ std::string>>
62
+ results;
62
63
63
64
uint32_t task_count = request->count ();
64
65
const auto &task_to_ctld = request->task ();
@@ -73,9 +74,14 @@ grpc::Status CraneCtldServiceImpl::SubmitBatchTasks(
73
74
}
74
75
75
76
for (auto &res : results) {
76
- if (res.has_value ())
77
- response->mutable_task_id_list ()->Add (res.value ().get ());
78
- else
77
+ if (res.has_value ()) {
78
+ auto submit_res = res.value ().get ();
79
+ if (submit_res.has_value ())
80
+ response->mutable_task_id_list ()->Add (submit_res.value ());
81
+ else
82
+ response->mutable_reason_list ()->Add (
83
+ std::string (CraneErrStr (submit_res.error ())));
84
+ } else
79
85
response->mutable_reason_list ()->Add (res.error ());
80
86
}
81
87
@@ -1086,8 +1092,13 @@ grpc::Status CraneCtldServiceImpl::CforedStream(
1086
1092
m_ctld_server_->SubmitTaskToScheduler (std::move (task));
1087
1093
result::result<task_id_t , std::string> result;
1088
1094
if (submit_result.has_value ()) {
1089
- result = result::result<task_id_t , std::string>{
1090
- submit_result.value ().get ()};
1095
+ auto submit_final_result = submit_result.value ().get ();
1096
+ if (submit_final_result.has_value ()) {
1097
+ result = result::result<task_id_t , std::string>{
1098
+ submit_final_result.value ()};
1099
+ } else {
1100
+ result = result::fail (CraneErrStr (submit_final_result.error ()));
1101
+ }
1091
1102
} else {
1092
1103
result = result::fail (submit_result.error ());
1093
1104
}
@@ -1210,7 +1221,7 @@ CtldServer::CtldServer(const Config::CraneCtldListenConf &listen_conf) {
1210
1221
signal (SIGINT, &CtldServer::signal_handler_func);
1211
1222
}
1212
1223
1213
- result::result<std::future<task_id_t >, std::string>
1224
+ result::result<std::future<result::result< task_id_t , CraneErr> >, std::string>
1214
1225
CtldServer::SubmitTaskToScheduler (std::unique_ptr<TaskInCtld> task) {
1215
1226
CraneErr err;
1216
1227
@@ -1260,7 +1271,7 @@ CtldServer::SubmitTaskToScheduler(std::unique_ptr<TaskInCtld> task) {
1260
1271
1261
1272
if (err == CraneErr::kOk ) {
1262
1273
task->SetSubmitTime (absl::Now ());
1263
- std::future<task_id_t > future =
1274
+ std::future<result::result< task_id_t , CraneErr> > future =
1264
1275
g_task_scheduler->SubmitTaskAsync (std::move (task));
1265
1276
return {std::move (future)};
1266
1277
}
0 commit comments