diff options
| author | Jan Safranek <jsafrane@redhat.com> | 2013-04-16 12:20:34 +0200 |
|---|---|---|
| committer | Jan Safranek <jsafrane@redhat.com> | 2013-04-16 13:03:47 +0200 |
| commit | 05d7ef102e0af91d342c2cb05998a0f8dce91dc8 (patch) | |
| tree | 8c42f098529a704af7959a3cdef804803c6acac0 /src/python | |
| parent | bc058e76b5379196462cda85b91e44bc45dfab34 (diff) | |
| download | openlmi-providers-05d7ef102e0af91d342c2cb05998a0f8dce91dc8.tar.gz openlmi-providers-05d7ef102e0af91d342c2cb05998a0f8dce91dc8.tar.xz openlmi-providers-05d7ef102e0af91d342c2cb05998a0f8dce91dc8.zip | |
Use monotonic clock for job expiration.
Job expiration timer should not be influenced by admin changing date or time.
Diffstat (limited to 'src/python')
| -rw-r--r-- | src/python/openlmi/common/JobManager.py | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/python/openlmi/common/JobManager.py b/src/python/openlmi/common/JobManager.py index 7122a27..6dd26ba 100644 --- a/src/python/openlmi/common/JobManager.py +++ b/src/python/openlmi/common/JobManager.py @@ -141,16 +141,18 @@ class Job(object): # State of the job self.job_state = self.STATE_QUEUED - # Last change of job state - self.time_of_last_state_change = self.time_submitted + # Last change of job state, wall clock time + self.clocktime_of_last_state_change = self.time_submitted - # Duration of the job in RUNNING state + # Duration of the job in RUNNING state (in seconds) self.elapsed_time = None - # When the job started (= switched to RUNNING) - self.start_time = None - # When the job finished (= switched from RUNNING) - self.finish_time = None + # When the job started (= switched to RUNNING), wall clock time + self.start_clocktime = None + # When the job started (= switched to RUNNING), monotonic clock time + self.start_monotime = None + # When the job finished (= switched from RUNNING), monotonic clock time + self.finish_monotime = None # Array of CIMInstanceNames of affected elements, so we can # enumerate associations to them. @@ -275,10 +277,12 @@ class Job(object): if (self.job_state not in self.FINAL_STATES and new_state in self.FINAL_STATES): # Remember finish time - self.finish_time = datetime.utcnow() + self.finish_clocktime = datetime.utcnow() + self.finish_monotime = self.timer_manager.now() # Remember job execution time. - if self.start_time: - self.elapsed_time = self.finish_time - self.start_time + if self.start_monotime: + self.elapsed_time = self.finish_monotime \ + - self.start_monotime # Send indication if self.job_state == self.STATE_FAILED: indication_ids.append(JobManager.IND_JOB_FAILED) @@ -287,9 +291,10 @@ class Job(object): # Check if the job has just started if new_state == self.STATE_RUNNING: - self.start_time = datetime.utcnow() + self.start_clocktime = datetime.utcnow() + self.start_monotime = self.timer_manager.now() - self.time_of_last_state_change = datetime.now() + self.clocktime_of_last_state_change = datetime.now() self.job_state = new_state if percent is None: @@ -303,7 +308,7 @@ class Job(object): if self.percent_complete != percent: # Remember to send indications if not send_indication: - self.time_of_last_state_change = datetime.now() + self.clocktime_of_last_state_change = datetime.now() prev_instance = self.job_manager.get_job_instance(self) send_indication = True indication_ids.append(JobManager.IND_JOB_PERCENT_UPDATED) @@ -345,9 +350,14 @@ class Job(object): # Start the new timer. if self.delete_on_completion: - now = datetime.utcnow() - passed = now - self.finish_time - timeout = self.time_before_removal - passed.total_seconds() + now = self.timer_manager.now() + passed = now - self.finish_monotime + timeout = self.time_before_removal - passed + if timeout <= 0: + # Just in case... + self._expire() + return + cmpi_logging.logger.debug("Starting timer for job %s: '%s' for %f" " seconds" % (self.the_id, self.job_name, timeout)) self.timer = self.timer_manager.create_timer( @@ -974,9 +984,9 @@ class LMI_ConcreteJob(CIMProvider2): value=None, type='datetime') - if job.time_of_last_state_change: + if job.clocktime_of_last_state_change: model['TimeOfLastStateChange'] = pywbem.CIMDateTime( - job.time_of_last_state_change) + job.clocktime_of_last_state_change) else: model['TimeOfLastStateChange'] = pywbem.CIMProperty( name='TimeOfLastStateChange', @@ -984,7 +994,8 @@ class LMI_ConcreteJob(CIMProvider2): type='datetime') if job.elapsed_time: - model['ElapsedTime'] = pywbem.CIMDateTime(job.elapsed_time) + elapsed_time = timedelta(seconds=job.elapsed_time) + model['ElapsedTime'] = pywbem.CIMDateTime(elapsed_time) else: model['ElapsedTime'] = pywbem.CIMProperty( name='ElapsedTime', @@ -994,8 +1005,8 @@ class LMI_ConcreteJob(CIMProvider2): model['Description'] = job.job_name model['LocalOrUtcTime'] = self.Values.LocalOrUtcTime.UTC_Time model['PercentComplete'] = pywbem.Uint16(job.percent_complete) - if job.start_time: - model['StartTime'] = pywbem.CIMDateTime(job.start_time) + if job.start_clocktime: + model['StartTime'] = pywbem.CIMDateTime(job.start_clocktime) else: model['StartTime'] = pywbem.CIMProperty( name='StartTime', |
