JobWatcher.cpp 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/std/containers/vector.h>
  9. #include <AzCore/std/string/string.h>
  10. #include <AzCore/Outcome/Outcome.h>
  11. #include <AzToolsFramework/API/EditorAssetSystemAPI.h> // for AssetSystemJobRequestBus
  12. #include <AzToolsFramework/Debug/TraceContext.h>
  13. #include <SceneAPI/SceneUI/CommonWidgets/JobWatcher.h>
  14. namespace AZ
  15. {
  16. namespace SceneAPI
  17. {
  18. namespace SceneUI
  19. {
  20. const int JobWatcher::s_jobQueryInterval = 750; // ms
  21. JobWatcher::JobWatcher(const AZStd::string& sourceAssetFullPath, Uuid traceTag)
  22. : m_jobQueryTimer(new QTimer(this))
  23. , m_sourceAssetFullPath(sourceAssetFullPath)
  24. , m_traceTag(traceTag)
  25. {
  26. connect(m_jobQueryTimer, &QTimer::timeout, this, &JobWatcher::OnQueryJobs);
  27. }
  28. void JobWatcher::StartMonitoring()
  29. {
  30. m_jobQueryTimer->start(s_jobQueryInterval);
  31. }
  32. void JobWatcher::OnQueryJobs()
  33. {
  34. using namespace AzToolsFramework;
  35. using namespace AzToolsFramework::AssetSystem;
  36. AZ_TraceContext("Tag", m_traceTag);
  37. // Query for the relevant jobs
  38. Outcome<AssetSystem::JobInfoContainer> result = Failure();
  39. AssetSystemJobRequestBus::BroadcastResult(result, &AssetSystemJobRequestBus::Events::GetAssetJobsInfo, m_sourceAssetFullPath, true);
  40. if (!result.IsSuccess())
  41. {
  42. m_jobQueryTimer->stop();
  43. emit JobQueryFailed("Failed to retrieve job information from Asset Processor.");
  44. return;
  45. }
  46. JobInfoContainer& allJobs = result.GetValue();
  47. if (allJobs.empty())
  48. {
  49. m_jobQueryTimer->stop();
  50. emit JobQueryFailed("Queued file didn't produce any jobs.");
  51. return;
  52. }
  53. bool allFinished = true;
  54. for (const JobInfo& job : allJobs)
  55. {
  56. AZ_Assert(job.m_status != JobStatus::Any,
  57. "The 'Any' status for job should be exclusive to the database and never be a result to a query.");
  58. if (job.m_status != JobStatus::Queued && job.m_status != JobStatus::InProgress)
  59. {
  60. if (AZStd::find(m_reportedJobs.begin(), m_reportedJobs.end(), job.m_jobRunKey) == m_reportedJobs.end())
  61. {
  62. bool wasSuccessful = job.m_status == AzToolsFramework::AssetSystem::JobStatus::Completed;
  63. Outcome<AZStd::string> logFetchResult = Failure();
  64. AssetSystemJobRequestBus::BroadcastResult(logFetchResult, &AssetSystemJobRequestBus::Events::GetJobLog, job.m_jobRunKey);
  65. emit JobProcessingComplete(job.m_platform, job.m_jobRunKey, wasSuccessful,
  66. logFetchResult.IsSuccess() ? logFetchResult.GetValue() : "");
  67. m_reportedJobs.push_back(job.m_jobRunKey);
  68. }
  69. }
  70. else
  71. {
  72. allFinished = false;
  73. }
  74. }
  75. if (allFinished)
  76. {
  77. m_jobQueryTimer->stop();
  78. emit AllJobsComplete();
  79. }
  80. }
  81. } // namespace SceneUI
  82. } // namespace SceneAPI
  83. } // namespace AZ
  84. #include <CommonWidgets/moc_JobWatcher.cpp>