Пример #1
0
        def _get_link_transactional(key):

            link = db.get(key)
            if link is None:
                raise db.TransactionFailedError()
            rawlink = link.link
            db.delete(link)
            return rawlink
Пример #2
0
def check_job_and_submit(app_context, incremental=True):
    """Determines whether an indexing job is running and submits if not."""
    indexing_job = IndexCourse(app_context, incremental=False)
    job_entity = IndexCourse(app_context).load()

    bad_status_codes = [jobs.STATUS_CODE_STARTED, jobs.STATUS_CODE_QUEUED]
    if job_entity and job_entity.status_code in bad_status_codes:
        raise db.TransactionFailedError('Index job is currently running.')

    indexing_job.non_transactional_submit()
Пример #3
0
def check_jobs_and_submit(job, app_context):
    """Determines whether an indexing job is running and submits if not."""
    indexing_job = IndexCourse(app_context).load()
    clearing_job = ClearIndex(app_context).load()

    bad_status_codes = [jobs.STATUS_CODE_STARTED, jobs.STATUS_CODE_QUEUED]
    if ((indexing_job and indexing_job.status_code in bad_status_codes) or
        (clearing_job and clearing_job.status_code in bad_status_codes)):
        raise db.TransactionFailedError('Index job is currently running.')
    else:
        job.non_transactional_submit()
Пример #4
0
 def increment(cls, name, num_shards, downward=False):
     index = random.randint(1, num_shards)
     shard_key_name = 'Shard' + name + str(index)
     def get_or_create_shard():
         shard = CounterShard.get_by_key_name(shard_key_name)
         if shard is None:
             shard = CounterShard(key_name=shard_key_name, 
                                  name=name)
         if downward:
             shard.count -= 1
         else:
             shard.count += 1
         key = shard.put()
     try:
         db.run_in_transaction(get_or_create_shard)
         return True
     except db.TransactionFailedError():
         logging.error("CounterShard (%s, %d) - can't increment", 
                       name, num_shards)
         return False