7 #include "packager/app/job_manager.h" 9 #include "packager/app/libcrypto_threading.h" 10 #include "packager/media/origin/origin_handler.h" 15 Job::Job(
const std::string& name, std::shared_ptr<OriginHandler> work)
17 work_(
std::move(work)),
18 wait_(
base::WaitableEvent::ResetPolicy::MANUAL,
19 base::WaitableEvent::InitialState::NOT_SIGNALED) {
28 status_ = work_->Run();
32 void JobManager::Add(
const std::string& name,
33 std::shared_ptr<OriginHandler> handler) {
37 job_entries_.push_back({name, std::move(handler)});
40 Status JobManager::InitializeJobs() {
42 for (
const JobEntry& job_entry : job_entries_)
43 status.Update(job_entry.worker->Initialize());
48 for (
const JobEntry& job_entry : job_entries_)
49 jobs_.emplace_back(
new Job(job_entry.name, std::move(job_entry.worker)));
53 Status JobManager::RunJobs() {
59 std::vector<Job*> active_jobs;
60 std::vector<base::WaitableEvent*> active_waits;
64 for (
auto& job : jobs_) {
67 active_jobs.push_back(job.get());
68 active_waits.push_back(job->wait());
73 while (status.ok() && active_jobs.size()) {
77 base::WaitableEvent::WaitMany(active_waits.data(), active_waits.size());
78 Job* job = active_jobs[done];
81 status.Update(job->status());
84 active_jobs.erase(active_jobs.begin() + done);
85 active_waits.erase(active_waits.begin() + done);
90 for (
auto& job : active_jobs) {
94 for (
auto& job : active_jobs) {
101 void JobManager::CancelJobs() {
102 for (
auto& job : jobs_) {
All the methods that are virtual are virtual for mocking.