예제 #1
0
 def __isFirstExecution(self, taskName, retryCount):
     """ Ensures that the task has not been executed before. Meant to be run in a transaction. """
     firstExecution = False
     keyName = '%s--%s' % (taskName, retryCount)
     existingTaskName = _FantasmTaskSemaphore.get_by_key_name(keyName)
     if not existingTaskName:
         _FantasmTaskSemaphore(key_name=keyName).put()
         firstExecution = True
     return firstExecution
예제 #2
0
 def txn():
     """ lock in transaction to avoid races between Tasks """
     entity = _FantasmTaskSemaphore.get_by_key_name(self.semaphoreKey)
     if not entity:
         _FantasmTaskSemaphore(key_name=self.semaphoreKey, payload=payload).put()
         memcache.set(self.semaphoreKey, payload)
         return (True, payload)
     else:
         if entity.payload != payload:
             self.logger.critical("Run-once semaphore datastore payload write error.")
         memcache.set(self.semaphoreKey, entity.payload) # maybe reduces chance of ejection???
         return (False, entity.payload)
예제 #3
0
파일: lock.py 프로젝트: BobDohnal/fantasm
 def txn():
     """ lock in transaction to avoid races between Tasks """
     key = db.Key.from_path(_FantasmTaskSemaphore.kind(), self.semaphoreKey, namespace='')
     entity = db.get(key)
     if not entity:
         _FantasmTaskSemaphore(key=key, payload=payload).put()
         memcache.set(self.semaphoreKey, payload, namespace=None)
         self.logger.debug('Setting run-once semaphore. Semaphore key: "%s", payload: "%s".', self.semaphoreKey, payload)
         return (True, payload)
     else:
         if entity.payload != payload:
             self.logger.critical("Run-once semaphore datastore payload write error. Semaphore key: '%s', actual payload: '%s', expected payload: '%s'.", self.semaphoreKey, entity.payload, payload)
         memcache.set(self.semaphoreKey, entity.payload, namespace=None) # maybe reduces chance of ejection???
         return (False, entity.payload)
예제 #4
0
 def txn():
     """ lock in transaction to avoid races between Tasks """
     key = db.Key.from_path(_FantasmTaskSemaphore.kind(),
                            self.semaphoreKey,
                            namespace='')
     entity = db.get(key)
     if not entity:
         _FantasmTaskSemaphore(key=key, payload=payload).put()
         memcache.set(self.semaphoreKey, payload, namespace=None)
         self.logger.debug(
             'Setting run-once semaphore. Semaphore key: "%s", payload: "%s".',
             self.semaphoreKey, payload)
         return (True, payload)
     else:
         if entity.payload != payload:
             self.logger.critical(
                 "Run-once semaphore datastore payload write error. Semaphore key: '%s', actual payload: '%s', expected payload: '%s'.",
                 self.semaphoreKey, entity.payload, payload)
         memcache.set(
             self.semaphoreKey, entity.payload,
             namespace=None)  # maybe reduces chance of ejection???
         return (False, entity.payload)