diff options
author | Michael DeHaan <mdehaan@redhat.com> | 2008-01-15 18:02:05 -0500 |
---|---|---|
committer | Michael DeHaan <mdehaan@redhat.com> | 2008-01-15 18:02:05 -0500 |
commit | f5a6bfd4e4c2750ad221247eb31f3e8ff73edeec (patch) | |
tree | aad6c2cc1cfcf6ccc1a26a6313955c97ea75850d /func/overlord | |
parent | dc85cea9b1912ad2cbe59224050b8ae38b051167 (diff) | |
download | func-f5a6bfd4e4c2750ad221247eb31f3e8ff73edeec.tar.gz func-f5a6bfd4e4c2750ad221247eb31f3e8ff73edeec.tar.xz func-f5a6bfd4e4c2750ad221247eb31f3e8ff73edeec.zip |
Make job engine delete jobs older than 1 hour, and store jobs not in homedirs, so it doesn't
have to be called by a user that has a homedir.
Diffstat (limited to 'func/overlord')
-rw-r--r-- | func/overlord/jobthing.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/func/overlord/jobthing.py b/func/overlord/jobthing.py index d28e966..e405616 100644 --- a/func/overlord/jobthing.py +++ b/func/overlord/jobthing.py @@ -28,7 +28,11 @@ JOB_ID_RUNNING = 0 JOB_ID_FINISHED = 1 JOB_ID_LOST_IN_SPACE = 2 -DEFAULT_CACHE_DIR = "~/.func" +# how long to retain old job records in the job id database +RETAIN_INTERVAL = 60 * 60 + +# where to store the internal job id database +CACHE_DIR = "/var/lib/func" def __update_status(jobid, status, results, clear=False): return __access_status(jobid=jobid, status=status, results=results, write=True) @@ -36,12 +40,26 @@ def __update_status(jobid, status, results, clear=False): def __get_status(jobid): return __access_status(jobid=jobid, write=False) + +def __purge_old_jobs(storage): + """ + Deletes jobs older than RETAIN_INTERVAL seconds. + MINOR FIXME: this probably should be a more intelligent algorithm that only + deletes jobs if the database is too big and then only the oldest jobs + but this will work just as well. + """ + nowtime = time.time() + for x in storage.keys(): + create_time = float(x) + if nowtime - create_time > RETAIN_INTERVAL: + del storage[x] + def __access_status(jobid=0, status=0, results=0, clear=False, write=False): - dir = os.path.expanduser("~/.func") + dir = os.path.expanduser(CACHE_DIR) if not os.path.exists(dir): os.makedirs(dir) - filename = os.path.join(dir,"status") + filename = os.path.join(dir,"status-%s" % os.getuid()) internal_db = bsddb.btopen(filename, 'c', 0644 ) handle = open(filename,"r") @@ -54,10 +72,8 @@ def __access_status(jobid=0, status=0, results=0, clear=False, write=False): fcntl.flock(handle.fileno(), fcntl.LOCK_UN) return {} - # FIXME: the jobid is the time of the job, so deleting jobs - # that are older than a set time would be a very good idea. - if write: + __purge_old_jobs(storage) storage[str(jobid)] = (status, results) rc = jobid else: |