| 337 | } |
| 338 | |
| 339 | void TaskExecutionService::SendResult( |
| 340 | const std::string& taskId, sync::TaskStatus status, |
| 341 | const std::string& errorMessage) |
| 342 | { |
| 343 | using namespace audacity::network_manager; |
| 344 | using namespace rapidjson; |
| 345 | |
| 346 | try |
| 347 | { |
| 348 | auto& serviceConfig = GetServiceConfig(); |
| 349 | auto& oauthService = GetOAuthService(); |
| 350 | |
| 351 | if (!oauthService.HasAccessToken()) |
| 352 | return; |
| 353 | |
| 354 | Document document; |
| 355 | document.SetObject(); |
| 356 | |
| 357 | auto statusStr = TaskStatusToString(status); |
| 358 | document.AddMember( |
| 359 | "status", |
| 360 | Value(statusStr.c_str(), statusStr.size(), document.GetAllocator()), |
| 361 | document.GetAllocator()); |
| 362 | |
| 363 | if (status == sync::TaskStatus::Failed && !errorMessage.empty()) |
| 364 | { |
| 365 | document.AddMember( |
| 366 | "error", |
| 367 | Value(errorMessage.c_str(), errorMessage.size(), document.GetAllocator()), |
| 368 | document.GetAllocator()); |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | document.AddMember( |
| 373 | "error", Value().SetNull(), document.GetAllocator()); |
| 374 | } |
| 375 | |
| 376 | StringBuffer buffer; |
| 377 | Writer<StringBuffer> writer(buffer); |
| 378 | document.Accept(writer); |
| 379 | |
| 380 | Request request(serviceConfig.GetTaskResultUrl(taskId)); |
| 381 | |
| 382 | request.setHeader( |
| 383 | common_headers::ContentType, common_content_types::ApplicationJson); |
| 384 | request.setHeader( |
| 385 | common_headers::Accept, common_content_types::ApplicationJson); |
| 386 | |
| 387 | SetCommonHeaders(request); |
| 388 | SetOptionalHeaders(request); |
| 389 | |
| 390 | auto response = NetworkManager::GetInstance().doPost( |
| 391 | request, buffer.GetString(), buffer.GetSize()); |
| 392 | |
| 393 | // No need to handle the response, even on error we can't do anything |
| 394 | } |
| 395 | catch (...) |
| 396 | { |
no test coverage detected