diff options
author | Luke Macken <lmacken@redhat.com> | 2008-01-15 18:34:35 -0500 |
---|---|---|
committer | Luke Macken <lmacken@redhat.com> | 2008-01-15 18:34:35 -0500 |
commit | f1fe3fa3ca574a54563cd2cf2e967e87558edeb4 (patch) | |
tree | 21137e2c8029421212576494402f0ef5fc72a49b /func | |
parent | a433b0073efcbeb2028dceed5105cc40f5936ddf (diff) | |
parent | 41c2855da8dad5b6dfb0983fdbbc46fab25fe1df (diff) | |
download | third_party-func-f1fe3fa3ca574a54563cd2cf2e967e87558edeb4.tar.gz third_party-func-f1fe3fa3ca574a54563cd2cf2e967e87558edeb4.tar.xz third_party-func-f1fe3fa3ca574a54563cd2cf2e967e87558edeb4.zip |
Merge branch 'master' of ssh+git://git.fedorahosted.org/git/func
Diffstat (limited to 'func')
-rw-r--r-- | func/overlord/forkbomb.py | 6 | ||||
-rw-r--r-- | func/overlord/jobthing.py | 28 |
2 files changed, 25 insertions, 9 deletions
diff --git a/func/overlord/forkbomb.py b/func/overlord/forkbomb.py index 1ff529d..c30cc9e 100644 --- a/func/overlord/forkbomb.py +++ b/func/overlord/forkbomb.py @@ -22,7 +22,7 @@ import tempfile import fcntl DEFAULT_FORKS = 4 -DEFAULT_CACHE_DIR = "~/.func" +DEFAULT_CACHE_DIR = "/var/lib/func" def __get_storage(dir): """ @@ -31,7 +31,7 @@ def __get_storage(dir): dir = os.path.expanduser(dir) if not os.path.exists(dir): os.makedirs(dir) - return tempfile.mktemp(suffix='', prefix='tmp', dir=dir) + return tempfile.mktemp(suffix='', prefix='asynctmp', dir=dir) def __access_buckets(filename,clear,new_key=None,new_value=None): """ @@ -133,7 +133,7 @@ def batch_run(pool,callback,nforks=DEFAULT_FORKS,cachedir=DEFAULT_CACHE_DIR): if nforks <= 1: # modulus voodoo gets crazy otherwise and bad things happen nforks = 2 - shelf_file = __get_storage("~/.func") + shelf_file = __get_storage(cachedir) __access_buckets(shelf_file,True,None) buckets = __bucketize(pool, nforks) # print "DEBUG: buckets: %s" % buckets 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: |