diff options
author | Jan Safranek <jsafrane@redhat.com> | 2013-07-23 13:48:57 +0200 |
---|---|---|
committer | Jan Safranek <jsafrane@redhat.com> | 2013-07-23 13:48:57 +0200 |
commit | 57a2a48043577207ed9f1812373c862fe324f66a (patch) | |
tree | da58736a9707d6e37fa646c69c1382b4c5d77285 /src | |
parent | 5c14f1cc27d559e671118481f492f6c95732a5b0 (diff) | |
download | openlmi-providers-57a2a48043577207ed9f1812373c862fe324f66a.tar.gz openlmi-providers-57a2a48043577207ed9f1812373c862fe324f66a.tar.xz openlmi-providers-57a2a48043577207ed9f1812373c862fe324f66a.zip |
Allow for waiting for jobs.
Some storage actions needs to be synchronous (because of SMI-S), but can
influence running jobs.
Imagine asynchronous job for vgreduce to remove /dev/sda1 from a volume group
and while it runs, someone creates new partition table on /dev/sda, which is
synchronous, as per SMI-S. The running vgreduce won't be happy and some data
might get lost.
Solution is to put a job to create new partition table to the job queue as
usual, and synchronously wait for the job to finish.
Diffstat (limited to 'src')
-rw-r--r-- | src/python/lmi/common/JobManager.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/python/lmi/common/JobManager.py b/src/python/lmi/common/JobManager.py index 59e80e3..5ee59a9 100644 --- a/src/python/lmi/common/JobManager.py +++ b/src/python/lmi/common/JobManager.py @@ -202,6 +202,8 @@ class Job(object): self._cancelargs = None self._cancelkwargs = None + self._finished_event = threading.Event() + @cmpi_logging.trace_method def set_execute_action(self, callback, *args, **kwargs): """ @@ -266,6 +268,7 @@ class Job(object): self.affected_elements = affected_elements self.change_state(new_state, 100) self.unlock() + self._finished_event.set() @cmpi_logging.trace_method def change_state(self, new_state, percent=None): @@ -436,6 +439,7 @@ class Job(object): self.change_state(self.STATE_TERMINATED) if self._cancel: self._cancel(*(self._cancelargs), **(self._cancelkwargs)) + self._finished_event.set() @cmpi_logging.trace_method def get_name(self): @@ -581,6 +585,18 @@ class Job(object): inst[name] = value return inst + @cmpi_logging.trace_method + def wait_for_job(self, timeout=None): + """ + Block and wait until the job completes. + + :param timeout: (``float``) Number of seconds to wait for the job + to complete. + :rtype: ``bool`` - True, when the job is finished, False if the timeout + occurred. + """ + return self._finished_event.wait(timeout) + # pylint: disable-msg=R0903 class ReturnValueType(object): """ CIM_InstMethodCall.ReturnValueType values.""" |