X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fjob.cc;h=d3871bf7225da22ed1911416c1b2ee4df4cffd5d;hb=5428006e97b37d757a03c14024d7a0fb363bdcc6;hp=d446b3913208ee897913a27b1a938821258d9071;hpb=266fe11af7f3bdc194cfedf92db7352b7b68be97;p=dcpomatic.git diff --git a/src/lib/job.cc b/src/lib/job.cc index d446b3913..d3871bf72 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -34,13 +34,15 @@ using namespace boost; * @param o Options. * @param l A log that we can write to. */ -Job::Job (shared_ptr s, shared_ptr o, Log* l) +Job::Job (shared_ptr s, shared_ptr o, Log* l, shared_ptr req) : _fs (s) , _opt (o) , _log (l) + , _required (req) , _state (NEW) , _start_time (0) , _progress_unknown (false) + , _ran_for (0) { assert (_log); @@ -68,9 +70,7 @@ Job::run_wrapper () set_progress (1); set_state (FINISHED_ERROR); - stringstream s; - s << e.what() << "(" << filesystem::path (e.filename()).leaf() << ")"; - set_error (s.str ()); + set_error (String::compose ("%1 (%2)", e.what(), filesystem::path (e.filename()).leaf())); } catch (std::exception& e) { @@ -81,6 +81,13 @@ Job::run_wrapper () } } +bool +Job::is_new () const +{ + boost::mutex::scoped_lock lm (_state_mutex); + return _state == NEW; +} + /** @return true if the job is running */ bool Job::running () const @@ -121,6 +128,10 @@ Job::set_state (State s) { boost::mutex::scoped_lock lm (_state_mutex); _state = s; + + if (_state == FINISHED_OK || _state == FINISHED_ERROR) { + _ran_for = elapsed_time (); + } } /** A hack to work around our lack of cross-thread @@ -223,7 +234,7 @@ Job::set_error (string e) _error = e; } -/** Set that this job's progress will always be unknown */ +/** Say that this job's progress will always be unknown */ void Job::set_progress_unknown () { @@ -231,6 +242,7 @@ Job::set_progress_unknown () _progress_unknown = true; } +/** @return Human-readable status of this job */ string Job::status () const { @@ -244,7 +256,7 @@ Job::status () const } else if (!finished () && (t <= 10 || r == 0)) { s << rint (p * 100) << "%"; } else if (finished_ok ()) { - s << "OK (ran for " << seconds_to_hms (t) << ")"; + s << "OK (ran for " << seconds_to_hms (_ran_for) << ")"; } else if (finished_in_error ()) { s << "Error (" << error() << ")"; } @@ -252,6 +264,7 @@ Job::status () const return s.str (); } +/** @return An estimate of the remaining time for this job, in seconds */ int Job::remaining_time () const {