summaryrefslogtreecommitdiff
path: root/src/meetingtools/ac/__init__.py
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2012-10-04 15:39:08 +0200
committerLeif Johansson <leifj@sunet.se>2012-10-04 15:39:08 +0200
commit2bdad0ae7a3a6e4ec5116becd39910388b679ed2 (patch)
tree5afdfba0a93c1af50d53bdc245d57cc4053e109a /src/meetingtools/ac/__init__.py
parent873e7823970352d591deee5f67f47c5436ee0e84 (diff)
restructure
Diffstat (limited to 'src/meetingtools/ac/__init__.py')
-rw-r--r--src/meetingtools/ac/__init__.py57
1 files changed, 0 insertions, 57 deletions
diff --git a/src/meetingtools/ac/__init__.py b/src/meetingtools/ac/__init__.py
deleted file mode 100644
index 2bbd25f..0000000
--- a/src/meetingtools/ac/__init__.py
+++ /dev/null
@@ -1,57 +0,0 @@
-from meetingtools.ac.api import ACPClient
-import time
-from meetingtools.apps.cluster.models import acc_for_user
-from django.core.cache import cache
-from Queue import Queue
-import logging
-from django.contrib.auth.models import User
-
-_pools = {}
-
-MAXCALLS = 10
-MAXIDLE = 10
-
-class ClientPool(object):
-
- def __init__(self,acc,maxsize=0,increment=2):
- self._q = Queue(maxsize)
- self._acc = acc
- self._increment = increment
-
- def allocate(self):
- now = time.time()
- api = None
- while not api:
- if self._q.empty():
- for i in range(1,self._increment):
- logging.debug("adding instance %d" % i)
- api = ACPClient(self._acc.api_url,self._acc.user,self._acc.password,cpool=self)
- self._q.put_nowait(api)
-
- api = self._q.get()
- if api and (api.age > MAXCALLS or now - api.lastused > MAXIDLE):
- api = None
- return api
-
-# with ac_api_client(acc) as api
-# ...
-
-def ac_api_client(o):
- acc = o
- logging.debug("ac_api_client(%s)" % repr(o))
- if hasattr(o,'user') and isinstance(getattr(o,'user'),User):
- acc = acc_for_user(getattr(o,'user'))
- elif hasattr(o,'acc'):
- acc = getattr(o,'acc')
-
- tag = 'ac_api_client_%d' % acc.id
- pool = _pools.get(tag)
- if pool is None:
- pool = ClientPool(acc,maxsize=30)
- _pools[tag] = pool
-
- return pool.allocate()
-
-
-
- \ No newline at end of file