mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Get more accurate currnet time in local_cache
This commit is contained in:
parent
844e3f65bc
commit
9b61533b09
2 changed files with 2 additions and 7 deletions
|
@ -391,7 +391,6 @@ def clean_old_jobs():
|
|||
Clean out the old jobs from the job cache
|
||||
'''
|
||||
if __opts__['keep_jobs'] != 0:
|
||||
cur = time.time()
|
||||
jid_root = _job_dir()
|
||||
|
||||
if not os.path.exists(jid_root):
|
||||
|
@ -421,6 +420,7 @@ def clean_old_jobs():
|
|||
shutil.rmtree(t_path)
|
||||
elif os.path.isfile(jid_file):
|
||||
jid_ctime = os.stat(jid_file).st_ctime
|
||||
cur = time.time()
|
||||
hours_difference = (cur - jid_ctime) / 3600.0
|
||||
if hours_difference > __opts__['keep_jobs'] and os.path.exists(t_path):
|
||||
# Remove the entire t_path from the original JID dir
|
||||
|
@ -435,6 +435,7 @@ def clean_old_jobs():
|
|||
# Checking the time again prevents a possible race condition where
|
||||
# t_path JID dirs were created, but not yet populated by a jid file.
|
||||
t_path_ctime = os.stat(t_path).st_ctime
|
||||
cur = time.time()
|
||||
hours_difference = (cur - t_path_ctime) / 3600.0
|
||||
if hours_difference > __opts__['keep_jobs']:
|
||||
shutil.rmtree(t_path)
|
||||
|
|
|
@ -72,12 +72,6 @@ class LocalCacheCleanOldJobsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
# Make sure there are no files in the directory before continuing
|
||||
self.assertEqual(jid_file, None)
|
||||
|
||||
# Windows needs some time to release the file handles to the new temp
|
||||
# dir before trying to clean the job cache to avoid a race condition
|
||||
if salt.utils.is_windows():
|
||||
import time
|
||||
time.sleep(1)
|
||||
|
||||
# Call clean_old_jobs function, patching the keep_jobs value with a
|
||||
# very small value to force the call to clean the job.
|
||||
with patch.dict(local_cache.__opts__, {'keep_jobs': 0.00000001}):
|
||||
|
|
Loading…
Add table
Reference in a new issue