Skip to content

Commit 6682bc4

Browse files
committed
Handle absent jobs properly.
1 parent c4c52c0 commit 6682bc4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Controller.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,22 @@ Controller::ExpectedOrError<JobId> Controller::submit_( drogon::HttpRequestPtr r
9696

9797
Controller::ExpectedOrError<Job> Controller::getInfo_( drogon::HttpRequestPtr req )
9898
{
99-
const auto maybeJobId = req->getOptionalParameter<std::string>( "job_id" );
99+
const auto maybeJob
100+
= req->getOptionalParameter<std::string>( "job_id" )
101+
.and_then( [this] ( auto jobId ) -> std::optional<Job>
102+
{
103+
std::shared_lock lock( jobsMutex_ );
104+
auto it = jobs_.find( jobId );
105+
if ( it != jobs_.end() )
106+
return it->second;
107+
else
108+
return std::nullopt;
109+
} );
100110

101-
if ( !maybeJobId )
111+
if ( !maybeJob )
102112
return std::unexpected<Error>{ { k404NotFound, "Job is not found" } };
103113

104-
std::shared_lock lock( jobsMutex_ );
105-
return jobs_[*maybeJobId];
114+
return *maybeJob;
106115
}
107116

108117
drogon::HttpResponsePtr Controller::getResult_( drogon::HttpRequestPtr req )

0 commit comments

Comments
 (0)