Skip to content

Commit

Permalink
Handle absent jobs properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewerf committed Oct 11, 2024
1 parent c4c52c0 commit 6682bc4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,22 @@ Controller::ExpectedOrError<JobId> Controller::submit_( drogon::HttpRequestPtr r

Controller::ExpectedOrError<Job> Controller::getInfo_( drogon::HttpRequestPtr req )
{
const auto maybeJobId = req->getOptionalParameter<std::string>( "job_id" );
const auto maybeJob
= req->getOptionalParameter<std::string>( "job_id" )
.and_then( [this] ( auto jobId ) -> std::optional<Job>
{
std::shared_lock lock( jobsMutex_ );
auto it = jobs_.find( jobId );
if ( it != jobs_.end() )
return it->second;
else
return std::nullopt;
} );

if ( !maybeJobId )
if ( !maybeJob )
return std::unexpected<Error>{ { k404NotFound, "Job is not found" } };

std::shared_lock lock( jobsMutex_ );
return jobs_[*maybeJobId];
return *maybeJob;
}

drogon::HttpResponsePtr Controller::getResult_( drogon::HttpRequestPtr req )
Expand Down

0 comments on commit 6682bc4

Please sign in to comment.