Commits

Ciaran Farrell committed 76ac97f

Fix logic when returning busyblocks - remember to actually sleep and keep asking the Groupwise server until the server states that there are no outstanding calendars to be checked

  • Participants
  • Parent commits e331432

Comments (0)

Files changed (1)

File termine/gwise.py

       logger.debug(resp.status.description)
       raise GWFatalException,resp.status.description
 
-  def __parseBusyBlocks__(self,udict):
+  def __parseBusyBlocks__(self,udict,s=None,e=None):
     '''Use Dyck-Words type algorithm to find out what the available times
        are. Note that if a user has an appointment that _started_ before now,
        then this is going to be the first element in the list of blocks. Thus,
       resp = self.client.service.getFreeBusyRequest(sessionid)
       if int(resp.status.code)==0:
         outstanding = int(resp.freeBusyStats.outstanding)
-        #TODO: rather than the 'or' in the next line check each condition
-        #individually. That way the warning can be that the threshold time for
-        #getting responses from GW has been exceeded
-        users = resp.freeBusyInfo.user
-        for user in users:
-          # remember, conference rooms are users without displayName
-          if hasattr(user,'displayName'):
-            dn = user.displayName
-          else:
-            dn = ''
-          u[user.email] = {'email':user.email,'uuid':user.uuid,
-                          'displayName':dn,
-                          'blocks':user.blocks}
         if (outstanding == 0) or (datetime.now() >= e):
           self.client.service.closeFreeBusySessionRequest(sessionid)
           logger.debug('GW server says he is finished. Get out of here')
-          return self.__parseBusyBlocks__(u)
-          finished = True
-        
+          users = resp.freeBusyInfo.user
+          for user in users:
+            # remember, conference rooms are users without displayName
+            if hasattr(user,'displayName'):
+              dn = user.displayName
+            else:
+              dn = ''
+            u[user.email] = {'email':user.email,'uuid':user.uuid,
+                          'displayName':dn,
+                          'blocks':user.blocks}
+          return self.__parseBusyBlocks__(u,s=st,e=et)
+          finished = True # this will never be reached
+        else:
+          logger.debug('Groupwise is not finished looking up calendars...')
       if datetime.now() >= e:
-        return self.__parseBusyBlocks__(u)
+        logger.debug('Timeout exceeded - cancel calendar lookup now')
+        return self.__parseBusyBlocks__(u,s=st,e=et)
         finished = True
-      logger.debug('sleeping for 2 seconds before asking GW server again')
+      logger.debug('sleeping for 4 seconds before asking GW server again')
       sleep(4) # don't hammer the GW server too often
     return self.__parseBusyBlocks__(u,s=st,e=et)