当前位置: 首页>>代码示例>>Java>>正文


Java TransientFailureException类代码示例

本文整理汇总了Java中com.google.appengine.api.taskqueue.TransientFailureException的典型用法代码示例。如果您正苦于以下问题:Java TransientFailureException类的具体用法?Java TransientFailureException怎么用?Java TransientFailureException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TransientFailureException类属于com.google.appengine.api.taskqueue包,在下文中一共展示了TransientFailureException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadAllTasks

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/** Leases and returns all tasks from the queue with the specified tag tld, in batches. */
public static List<TaskHandle> loadAllTasks(Queue queue, String tld) {
  ImmutableList.Builder<TaskHandle> allTasks = new ImmutableList.Builder<>();
  int numErrors = 0;
  long backOff = backOffMillis;
  while (true) {
    try {
      List<TaskHandle> tasks = queue.leaseTasks(LeaseOptions.Builder
          .withTag(tld)
          .leasePeriod(LEASE_PERIOD.getMillis(), TimeUnit.MILLISECONDS)
          .countLimit(BATCH_SIZE));
      allTasks.addAll(tasks);
      if (tasks.isEmpty()) {
        return allTasks.build();
      }
    } catch (TransientFailureException | DeadlineExceededException e) {
      if (++numErrors >= 3) {
        throw new RuntimeException("Error leasing tasks", e);
      }
      Uninterruptibles.sleepUninterruptibly(backOff, TimeUnit.MILLISECONDS);
      backOff *= 2;
    }
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:25,代码来源:LordnTask.java

示例2: export

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
public void export(BigQueryMetric metric) {
  try {
    String hostname = modulesService.getVersionHostname("backend", null);
    TaskOptions opts =
        withUrl(MetricsExportAction.PATH)
            .header("Host", hostname)
            .param("insertId", idGenerator.get());
    for (Entry<String, String> entry : metric.getBigQueryRowEncoding().entrySet()) {
      opts.param(entry.getKey(), entry.getValue());
    }
    opts.param("tableId", metric.getTableId());
    queue.add(opts);
  } catch (TransientFailureException e) {
    // Log and swallow. We may drop some metrics here but this should be rare.
    logger.info(e, e.getMessage());
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:18,代码来源:BigQueryMetricsEnqueuer.java

示例3: deleteTasksWithRetry

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/** Deletes a list of tasks from the given queue using a retrier. */
private static void deleteTasksWithRetry(
    final List<DnsRefreshRequest> refreshRequests,
    final Queue queue,
    AsyncFlowMetrics asyncFlowMetrics,
    Retrier retrier,
    OperationResult result) {
  if (refreshRequests.isEmpty()) {
    return;
  }
  final List<TaskHandle> tasks =
      refreshRequests.stream().map(DnsRefreshRequest::task).collect(toImmutableList());
  retrier.callWithRetry(() -> queue.deleteTask(tasks), TransientFailureException.class);
  refreshRequests.forEach(
      r -> asyncFlowMetrics.recordAsyncFlowResult(DNS_REFRESH, result, r.requestedTime()));
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:RefreshDnsOnHostRenameAction.java

示例4: queueToIndex

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/**
 * @param name
 * @param id
 */
public static void queueToIndex (String name, Long id) {
	Queue queue = QueueFactory.getDefaultQueue();

	TaskOptions options = TaskOptions.Builder.withMethod(Method.POST)
			.url(INDEX_SEARCH_URL).param(ENTITY_NAME_KEY, name)
			.param(ENTITY_ID_KEY, id.toString());

	int retry = RETRY_COUNT;
	do {
		try {
			queue.add(options);

			// success no need to retry
			retry = 0;
		} catch (TransientFailureException ex) {
			retry--;
		}
	} while (retry > 0);
}
 
开发者ID:billy1380,项目名称:blogwt,代码行数:24,代码来源:SearchHelper.java

示例5: enqueueTask

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
@Override
public void enqueueTask(String taskName, Map<String, String[]> paramMap) {

  checkNotNull(taskName);

  final Queue queue = QueueFactory.getDefaultQueue();
  final TaskOptions options = TaskOptions.Builder.withUrl(String.format(PATH_ADMIN_TASK, taskName));

  for (Map.Entry<String, String[]> param : paramMap.entrySet()) {
    for (String value : param.getValue()) {
      options.param(param.getKey(), value);
    }
  }

  try {
    queue.add(options);
    LOGGER.info("Added admin task to queue {}", taskName);
  } catch (TransientFailureException tfe) {
    LOGGER.error("Run admin task fail {} ", tfe.getMessage());
  }

}
 
开发者ID:Wadpam,项目名称:guja,代码行数:23,代码来源:GAEAdminTaskQueue.java

示例6: transactCommitLoggedWork

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/**
 * Transact with commit logs and retry with exponential backoff.
 *
 * <p>This method is broken out from {@link #transactNew(Work)} for testing purposes.
 */
@VisibleForTesting
<R> R transactCommitLoggedWork(CommitLoggedWork<R> work) {
  long baseRetryMillis = getBaseOfyRetryDuration().getMillis();
  for (long attempt = 0, sleepMillis = baseRetryMillis;
      true;
      attempt++, sleepMillis *= 2) {
    try {
      ofy().transactNew(work);
      return work.getResult();
    } catch (TransientFailureException
        | TimestampInversionException
        | DatastoreTimeoutException
        | DatastoreFailureException e) {
      // TransientFailureExceptions come from task queues and always mean nothing committed.
      // TimestampInversionExceptions are thrown by our code and are always retryable as well.
      // However, Datastore exceptions might get thrown even if the transaction succeeded.
      if ((e instanceof DatastoreTimeoutException || e instanceof DatastoreFailureException)
          && checkIfAlreadySucceeded(work)) {
        return work.getResult();
      }
      if (attempt == NUM_RETRIES) {
        throw e;  // Give up.
      }
      sleeper.sleepUninterruptibly(Duration.millis(sleepMillis));
      logger.infofmt(e, "Retrying %s, attempt %s", e.getClass().getSimpleName(), attempt);
    }
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:34,代码来源:Ofy.java

示例7: map

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
@Override
public final void map(@Nullable final DomainResource domain) {
  if (domain == null) {
    // Emit a single value so that the reducer always runs.  The key and value don't matter.
    emit(true, true);
    return;
  }
  Key<HostResource> referencingHostKey = null;
  for (DnsRefreshRequest request : refreshRequests) {
    if (isActive(domain, request.lastUpdateTime())
        && domain.getNameservers().contains(request.hostKey())) {
      referencingHostKey = request.hostKey();
      break;
    }
  }
  if (referencingHostKey != null) {
    retrier.callWithRetry(
        () -> dnsQueue.addDomainRefreshTask(domain.getFullyQualifiedDomainName()),
        TransientFailureException.class);
    logger.infofmt(
        "Enqueued DNS refresh for domain %s referenced by host %s.",
        domain.getFullyQualifiedDomainName(), referencingHostKey);
    getContext().incrementCounter("domains refreshed");
  } else {
    getContext().incrementCounter("domains not refreshed");
  }

  // Don't catch errors -- we allow the mapreduce to terminate on any errors that can't be
  // resolved by retrying the transaction. The reducer only fires if the mapper completes
  // without errors, meaning that it is acceptable to delete all tasks.
}
 
开发者ID:google,项目名称:nomulus,代码行数:32,代码来源:RefreshDnsOnHostRenameAction.java

示例8: deleteStaleTasksWithRetry

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/**
 * Deletes a list of tasks associated with deletion requests from the async delete queue using a
 * retrier.
 */
private void deleteStaleTasksWithRetry(final List<DeletionRequest> deletionRequests) {
  if (deletionRequests.isEmpty()) {
    return;
  }
  final List<TaskHandle> tasks =
      deletionRequests.stream().map(DeletionRequest::task).collect(toImmutableList());
  retrier.callWithRetry(() -> queue.deleteTask(tasks), TransientFailureException.class);
  deletionRequests.forEach(
      deletionRequest ->
          asyncFlowMetrics.recordAsyncFlowResult(
              deletionRequest.getMetricOperationType(),
              OperationResult.STALE,
              deletionRequest.requestedTime()));
}
 
开发者ID:google,项目名称:nomulus,代码行数:19,代码来源:DeleteContactsAndHostsAction.java

示例9: leaseTasks

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/** Returns handles for a batch of tasks, leased for the specified duration. */
public List<TaskHandle> leaseTasks(Duration leaseDuration) {
  try {
    int numTasks = queue.fetchStatistics().getNumTasks();
    logger.logfmt(
        (numTasks >= leaseTasksBatchSize) ? Level.WARNING : Level.INFO,
        "There are %d tasks in the DNS queue '%s'.",
        numTasks,
        DNS_PULL_QUEUE_NAME);
    return queue.leaseTasks(leaseDuration.getMillis(), MILLISECONDS, leaseTasksBatchSize);
  } catch (TransientFailureException | DeadlineExceededException e) {
    logger.severe(e, "Failed leasing tasks too fast");
    return ImmutableList.of();
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:16,代码来源:DnsQueue.java

示例10: deleteTask

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/** Delete the task, removing it from the queue permanently. */
public void deleteTask(TaskHandle task) {
  try {
    queue.deleteTask(task);
  } catch (TransientFailureException | DeadlineExceededException e) {
    logger.severe(e, "Failed deleting tasks too fast");
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:9,代码来源:DnsQueue.java

示例11: deleteTasks

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/** Delete a list of tasks, removing them from the queue permanently. */
public void deleteTasks(List<TaskHandle> tasks) {
  try {
    queue.deleteTask(tasks);
  } catch (TransientFailureException | DeadlineExceededException e) {
    logger.severe(e, "Failed deleting tasks too fast");
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:9,代码来源:DnsQueue.java

示例12: enqueue

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
/**
 * Adds tasks to an App Engine task queue in a reliable manner.
 *
 * <p>This is the same as {@link Queue#add(Iterable)} except it'll automatically retry with
 * exponential backoff if {@link TransientFailureException} is thrown.
 *
 * @throws TransientFailureException if retrying failed for the maximum period of time, or an
 *     {@link InterruptedException} told us to stop trying
 * @return successfully enqueued tasks
 */
public List<TaskHandle> enqueue(final Queue queue, final Iterable<TaskOptions> tasks) {
  return retrier.callWithRetry(
      () -> {
        for (TaskOptions task : tasks) {
          logger.infofmt(
              "Enqueuing queue='%s' endpoint='%s'", queue.getQueueName(), task.getUrl());
        }
        return queue.add(tasks);
      },
      TransientFailureException.class);
}
 
开发者ID:google,项目名称:nomulus,代码行数:22,代码来源:TaskEnqueuer.java

示例13: test_loadAllTasks_retryLogic_thirdTrysTheCharm

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test_loadAllTasks_retryLogic_thirdTrysTheCharm() throws Exception {
  Queue queue = mock(Queue.class);
  TaskHandle task = new TaskHandle(TaskOptions.Builder.withTaskName("blah"), "blah");
  when(queue.leaseTasks(any(LeaseOptions.class)))
      .thenThrow(TransientFailureException.class)
      .thenThrow(DeadlineExceededException.class)
      .thenReturn(ImmutableList.of(task), ImmutableList.of());
  assertThat(LordnTask.loadAllTasks(queue, "tld")).containsExactly(task);
}
 
开发者ID:google,项目名称:nomulus,代码行数:12,代码来源:LordnTaskTest.java

示例14: test_loadAllTasks_retryLogic_allFailures

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test_loadAllTasks_retryLogic_allFailures() throws Exception {
  Queue queue = mock(Queue.class);
  when(queue.leaseTasks(any(LeaseOptions.class))).thenThrow(TransientFailureException.class);
  RuntimeException thrown =
      expectThrows(RuntimeException.class, () -> LordnTask.loadAllTasks(queue, "tld"));
  assertThat(thrown).hasMessageThat().contains("Error leasing tasks");
}
 
开发者ID:google,项目名称:nomulus,代码行数:10,代码来源:LordnTaskTest.java

示例15: testTransact_transientFailureException_retries

import com.google.appengine.api.taskqueue.TransientFailureException; //导入依赖的package包/类
@Test
public void testTransact_transientFailureException_retries() {
  assertThat(ofy().transact(new Work<Integer>() {

    int count = 0;

    @Override
    public Integer run() {
      count++;
      if (count == 3) {
        return count;
      }
      throw new TransientFailureException("");
    }})).isEqualTo(3);
}
 
开发者ID:google,项目名称:nomulus,代码行数:16,代码来源:OfyTest.java


注:本文中的com.google.appengine.api.taskqueue.TransientFailureException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。