7 #ifndef PACKAGER_APP_JOB_MANAGER_H_
8 #define PACKAGER_APP_JOB_MANAGER_H_
16 #include <absl/synchronization/mutex.h>
18 #include <packager/status.h>
30 typedef std::function<void(
Job*)> OnCompleteFunction;
32 Job(
const std::string& name,
33 std::shared_ptr<OriginHandler> work,
34 OnCompleteFunction on_complete);
38 const Status& Initialize();
61 const Status& status()
const {
return status_; }
64 const std::string& name()
const {
return name_; }
68 Job& operator=(
const Job&) =
delete;
71 std::shared_ptr<OriginHandler> work_;
72 OnCompleteFunction on_complete_;
73 std::unique_ptr<std::thread> thread_;
85 explicit JobManager(std::unique_ptr<SyncPointQueue> sync_points);
92 void Add(
const std::string& name, std::shared_ptr<OriginHandler> handler);
97 Status InitializeJobs();
102 virtual Status RunJobs();
114 void OnJobComplete(
Job* job);
118 std::unique_ptr<SyncPointQueue> sync_points_;
120 std::vector<std::unique_ptr<Job>> jobs_;
123 std::map<Job*, bool> complete_ ABSL_GUARDED_BY(mutex_);
124 absl::CondVar any_job_complete_ ABSL_GUARDED_BY(mutex_);
All the methods that are virtual are virtual for mocking.