Пример #1
0
    def get_or_create(self, dte, rjson, inthread=False):
        '''
        Create or return an element associated with date 'dte'
        dte      date
        rjson    boolean. If true a check on timestamp is performed
        '''
        dte = get_livedate(dte)
        dt = dte.dateonly

        if rjson:
            lm = self.lastmodified()
            if lm > self.timestamp:
                self.timestamp = now()
                self.ts = dateseries()

        # thread safe creation
        self.__lock.acquire()
        try:
            if self.has_key(dt):
                return self.ts[dt]
            else:
                res = self.create(dte)
                if res:
                    self.ts[dt] = res
                self.build(res, inthread)
                return res
        except Exception, e:
            self.err(e)
            return None
Пример #2
0
 def get_or_create(self, dte, rjson, inthread = False):
     '''
     Create or return an element associated with date 'dte'
     dte      date
     rjson    boolean. If true a check on timestamp is performed
     '''
     dte = get_livedate(dte)
     dt  = dte.dateonly
     
     if rjson:
         lm  = self.lastmodified()
         if lm > self.timestamp:
             self.timestamp = now()
             self.ts        = dateseries()
     
     # thread safe creation
     self.__lock.acquire()
     try:
         if self.has_key(dt):
             return self.ts[dt]
         else:
             res = self.create(dte)
             if res:
                 self.ts[dt] = res
             self.build(res,inthread)
             return res
     except Exception, e:
         self.err(e)
         return None
Пример #3
0
 def timecheck(self):
     lm = Position.get_last_modified()
     ld = PortfolioDisplay.objects.get_last_modified()
     la = self.lastaccess
     if la:
         if lm > la or ld > la:
             self.flush()
     self.lastaccess = now()
Пример #4
0
 def __init__(self, code, cache):
     super(CacheElement, self).__init__(cache)
     self.timestamp = now()
     self.ts = dateseries()
     self.object = self.get_object(code)
     self.__lock = Lock()
Пример #5
0
 def __init__(self, code, cache):
     super(CacheElement,self).__init__(cache)
     self.timestamp = now()
     self.ts        = dateseries()
     self.object    = self.get_object(code)
     self.__lock    = Lock()