| 288 | } |
| 289 | |
| 290 | bool TaskExecutionService::AcknowledgeTask(const std::string& taskId) |
| 291 | { |
| 292 | using namespace audacity::network_manager; |
| 293 | using namespace rapidjson; |
| 294 | |
| 295 | try |
| 296 | { |
| 297 | auto& serviceConfig = GetServiceConfig(); |
| 298 | auto& oauthService = GetOAuthService(); |
| 299 | |
| 300 | if (!oauthService.HasAccessToken()) |
| 301 | return false; |
| 302 | |
| 303 | StringBuffer buffer; |
| 304 | |
| 305 | Request request(serviceConfig.GetTaskAckUrl(taskId)); |
| 306 | |
| 307 | request.setHeader( |
| 308 | common_headers::ContentType, common_content_types::ApplicationJson); |
| 309 | request.setHeader( |
| 310 | common_headers::Accept, common_content_types::ApplicationJson); |
| 311 | |
| 312 | SetCommonHeaders(request); |
| 313 | SetOptionalHeaders(request); |
| 314 | |
| 315 | auto response = NetworkManager::GetInstance().doPost( |
| 316 | request, buffer.GetString(), buffer.GetSize()); |
| 317 | |
| 318 | const int maxWaitSeconds = 10; |
| 319 | for (int i = 0; i < maxWaitSeconds && !response->isFinished() && !mStopRequested; ++i) |
| 320 | { |
| 321 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 322 | } |
| 323 | |
| 324 | if (!response->isFinished()) |
| 325 | { |
| 326 | response->abort(); |
| 327 | return false; |
| 328 | } |
| 329 | |
| 330 | int httpCode = response->getHTTPCode(); |
| 331 | return httpCode >= 200 && httpCode < 300; |
| 332 | } |
| 333 | catch (...) |
| 334 | { |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | void TaskExecutionService::SendResult( |
| 340 | const std::string& taskId, sync::TaskStatus status, |
nothing calls this directly
no test coverage detected