diff options
| author | Jan Safranek <jsafrane@redhat.com> | 2013-04-15 14:47:18 +0200 |
|---|---|---|
| committer | Jan Safranek <jsafrane@redhat.com> | 2013-04-16 13:03:47 +0200 |
| commit | bc058e76b5379196462cda85b91e44bc45dfab34 (patch) | |
| tree | 9548cdf060a54b310f06049a851d64116f8f9708 /src/python | |
| parent | ace33f58e62dad9463211f980595270f262848f0 (diff) | |
| download | openlmi-providers-bc058e76b5379196462cda85b91e44bc45dfab34.tar.gz openlmi-providers-bc058e76b5379196462cda85b91e44bc45dfab34.tar.xz openlmi-providers-bc058e76b5379196462cda85b91e44bc45dfab34.zip | |
Use TimerManager where appropriate.
Diffstat (limited to 'src/python')
| -rw-r--r-- | src/python/openlmi/common/JobManager.py | 25 | ||||
| -rw-r--r-- | src/python/openlmi/common/TimerManager.py | 2 |
2 files changed, 18 insertions, 9 deletions
diff --git a/src/python/openlmi/common/JobManager.py b/src/python/openlmi/common/JobManager.py index bb6fed8..7122a27 100644 --- a/src/python/openlmi/common/JobManager.py +++ b/src/python/openlmi/common/JobManager.py @@ -100,6 +100,7 @@ class Job(object): created for it. """ self.job_manager = job_manager + self.timer_manager = job_manager.timer_manager # Unique ID self.the_id = job_manager.get_next_id() @@ -317,13 +318,15 @@ class Job(object): self._restart_timer() self.unlock() + @cmpi_logging.trace_method def _expire(self): """ Callback when a Job completes and time_before_removal second passed. The job gets removed from its JobManager. """ - # We cannot log here, this method is executed in job's Timer thread, - # which is not registered at the cimom. + cmpi_logging.logger.debug("Job %s: %s expired" + % (self.the_id, self.job_name)) + self.job_manager.remove_job(self) @cmpi_logging.trace_method @@ -347,8 +350,10 @@ class Job(object): timeout = self.time_before_removal - passed.total_seconds() cmpi_logging.logger.debug("Starting timer for job %s: '%s' for %f" " seconds" % (self.the_id, self.job_name, timeout)) - self.timer = threading.Timer(timeout, self._expire) - self.timer.start() + self.timer = self.timer_manager.create_timer( + "Job " + self.job_name, + callback=self._expire) + self.timer.start(timeout) @cmpi_logging.trace_method def lock(self): @@ -600,7 +605,8 @@ class JobManager(object): Where ``<name>`` is prefix of your classes, for example 'Storage' - 2. During initialization, create ``JobManager``. + 2. During initialization, initialize ``TimerManager`` and create + ``JobManager``. 3. When needed. create new Job instance: @@ -636,7 +642,7 @@ class JobManager(object): IND_JOB_CREATED = "Created" @cmpi_logging.trace_method - def __init__(self, name, namespace, indication_manager): + def __init__(self, name, namespace, indication_manager, timer_manager): """ Initialize new Manager. It automatically registers all job-related filters to indication_manager and starts a worker thread. @@ -647,6 +653,7 @@ class JobManager(object): :param namespace: (``string``) Namespace of all providers. :param indication_manager: (``IndicationManager``): a manager where indications and filters should be added. + :param timer_manager: (``TimerManager``): Timer manager instance. """ # List of all jobs. Dictionary job_id -> Job. self.jobs = {} @@ -660,6 +667,7 @@ class JobManager(object): self.providers = {} self.namespace = namespace self.indication_manager = indication_manager + self.timer_manager = timer_manager # Start the worker thread (don't forget to register it at CIMOM) self.worker = threading.Thread(target=self._worker_main) @@ -795,6 +803,7 @@ class JobManager(object): self.indication_manager.send_instmodification(prev_instance, current_instance, _id) + @cmpi_logging.trace_method def remove_job(self, job): """ Remove existing job. Note that jobs are removed automatically after a @@ -802,8 +811,8 @@ class JobManager(object): :param job: (``Job``) Job to remove. """ - # We cannot log here, this method is executed in job's Timer thread, - # which is not registered at the cimom. + cmpi_logging.logger.debug("Job %s: '%s' removed from queue." + % (job.the_id, job.job_name)) del self.jobs[job.the_id] # The job may still be in the queue! # There is no way, how to remove it, it will be skipped by the diff --git a/src/python/openlmi/common/TimerManager.py b/src/python/openlmi/common/TimerManager.py index 99f35d2..5eb39ae 100644 --- a/src/python/openlmi/common/TimerManager.py +++ b/src/python/openlmi/common/TimerManager.py @@ -263,7 +263,7 @@ class TimerManager(singletonmixin.Singleton): now = self.now() cmpi_logging.logger.trace_info( "Timer: Checking for expired, now=%f." % (now)) - expired = [t for t in self_timers if t._expired(now)] + expired = [t for t in self._timers if t._expired(now)] # Call the callbacks (unlocked!). for t in expired: |
