def post(self): globalStop = int(self.request.get('globalStop')) startKey = int(self.request.get('startKey')) stopKey = int(self.request.get('stopKey')) startCue = meTools.buildTradeCueKey(startKey) stopCue = meTools.buildTradeCueKey(stopKey) # get last desire for these start stop Keys meSchema.desire.all().filter('CueKey IN', [startCue,stopCue]).filter('__key__ <', Key.from_path('desire','1000000_0000_00')).order('-__key__').get()
def doDesires(step, startKey=None, stopKey=None): global cvalDict if stopKey is None and startKey is None: startKey = 1 stopKey = int(meSchema.tradeCue.all(keys_only=True).order('-__key__').get().name()) elif stopKey is None or startKey is None: raise(BaseException('Must define both startKey and stopKey, or both must be None!')) # Check cachepy clock and sync with memcache if necessary. syncProcessCache(step,startKey,stopKey) # Construct cvalDict for this step. for stckID in [1,2,3,4]: deltakey = str(stckID) + "_" + str(step) cvalDict[deltakey] = calculateDeltas(stckID, step) medesires = [] count = 0 for i in range(startKey, stopKey + 1): cuekey = meTools.buildTradeCueKey(i) desires = doDesire(step, cuekey) if len(desires) != 0: medesires.extend(desires) meTools.batchPut(medesires) # Remove from global cvalDict since not sure how that will act with same running process. for stckID in [1,2,3,4]: del cvalDict[str(stckID) + '_' + str(step)]
def syncProcessCache(step,startKey,stopKey): clockKey = 'stepclock_' + str(startKey) + '_' + str(stopKey) stepclock = cachepy.get(clockKey, priority=1) memkeylist = [] if stepclock not in [step-1, step]: for i in range(startKey,stopKey + 1): for stckID in [1,2,3,4]: cuekey = meTools.buildTradeCueKey(i) recency_key = 'desire_' + cuekey + '_' + str(stckID) memkeylist.append(recency_key) recentDesires = memcache.get_multi(memkeylist) cachepy.set_multi(recentDesires, priority = 1) ''' for des in recentDesires: cachepy.set(des, recentDesires[des], priority=1) ''' cachepy.set(clockKey,step,priority=1) # Set cachepy clockKey to current step since synced with Memcache.