Package com.google.appengine.api.taskqueue

Examples of com.google.appengine.api.taskqueue.TaskOptions


      taskQueue.add(taskOptionsList);
    }
  }

  private TaskOptions toTaskOptions(Task task) {
    TaskOptions taskOptions = TaskOptions.Builder.withUrl(TaskHandler.HANDLE_TASK_URL);
    if (task.getOnBackend() != null) {
      taskOptions.header("Host",
          BackendServiceFactory.getBackendService().getBackendAddress(task.getOnBackend()));
    }
    addProperties(taskOptions, task.toProperties());
    String taskName = task.getName();
    if (null != taskName) {
      taskOptions.taskName(taskName);
    }
    Long delaySeconds = task.getDelaySeconds();
    if (null != delaySeconds) {
      taskOptions.countdownMillis(delaySeconds * 1000L);
    }
    return taskOptions;
  }
View Full Code Here


    return controller.combineResults(results.build());
  }

  private void scheduleControllerTask(Transaction tx, ShardedJobStateImpl<T, R> state) {
    ShardedJobSettings settings = state.getSettings();
    TaskOptions taskOptions = TaskOptions.Builder.withMethod(TaskOptions.Method.POST)
        .url(settings.getControllerPath())
        .param(JOB_ID_PARAM, state.getJobId())
        .param(SEQUENCE_NUMBER_PARAM, "" + state.getNextSequenceNumber())
        .countdownMillis(settings.getMillisBetweenPolls());
    if (settings.getControllerBackend() != null) {
      taskOptions.header("Host",
          BackendServiceFactory.getBackendService().getBackendAddress(
              settings.getControllerBackend()));
    }
    QueueFactory.getQueue(settings.getControllerQueueName()).add(tx, taskOptions);
  }
View Full Code Here

    QueueFactory.getQueue(settings.getControllerQueueName()).add(tx, taskOptions);
  }

  private void scheduleWorkerTask(Transaction tx,
      ShardedJobSettings settings, IncrementalTaskState<T, R> state) {
    TaskOptions taskOptions = TaskOptions.Builder.withMethod(TaskOptions.Method.POST)
        .url(settings.getWorkerPath())
        .param(TASK_ID_PARAM, state.getTaskId())
        .param(JOB_ID_PARAM, state.getJobId())
        .param(SEQUENCE_NUMBER_PARAM, "" + state.getNextSequenceNumber());
    if (settings.getWorkerBackend() != null) {
      taskOptions.header("Host",
          BackendServiceFactory.getBackendService().getBackendAddress(settings.getWorkerBackend()));
    }
    QueueFactory.getQueue(settings.getWorkerQueueName()).add(tx, taskOptions);
  }
View Full Code Here

    } else {
      // We maken een queue aan.
      Queue boodschappenQueue = QueueFactory
          .getQueue("boodschappen-queue");
      // We maken een task aan.
      TaskOptions options = TaskOptions.Builder
          .withUrl("/boodschappen-queue").param("user", userId)
          .method(Method.GET);
      // We ovegen een element toe aan de queue.
      boodschappenQueue.add(options);
    }
View Full Code Here

    public static Future<TaskHandle> addAsync(Queue selfQueue, Map<String, Object> params) {
        return selfQueue.addAsync(buildTaskOptions(params));
    }

    @SuppressWarnings("unchecked") private static TaskOptions buildTaskOptions(Map<String, Object> params) {
        TaskOptions options = TaskOptions.Builder.withDefaults();
        for(Entry<String, Object> e : params.entrySet()) {
            String key = e.getKey();
            Object value = e.getValue();
            switch (key) {
                case "countdownMillis":
                    options = options.countdownMillis(((Number)value).longValue());
                    break;
                case "etaMillis":
                    options = options.etaMillis(((Number)value).longValue());
                    break;
                case "taskName":
                    options = options.taskName(String.valueOf(value));
                    break;
                case "url":
                    options = options.url(String.valueOf(value));
                    break;
                case "headers":
                    if (value instanceof Map) {
                        for (Entry<String, String> header : ((Map<String, String>)value).entrySet()) {
                            options = options.header(header.getKey(), header.getValue());
                        }
                    } else {
                        throw new RuntimeException("The headers key/value pairs should be passed as a map.");
                    }
                    break;
                case "retryOptions":
                    if (value instanceof Map) {
                        RetryOptions retryOptions = RetryOptions.Builder.withDefaults();
                        for (Entry<String, Object> option : ((Map<String, Object>)value).entrySet()) {
                            switch (option.getKey()) {
                                case "taskRetryLimit":
                                    retryOptions.taskRetryLimit(((Number)option.getValue()).intValue());
                                    break;
                                case "taskAgeLimitSeconds":
                                    retryOptions.taskAgeLimitSeconds(((Number)option.getValue()).intValue());
                                    break;
                                case "minBackoffSeconds":
                                    retryOptions.minBackoffSeconds(((Number)option.getValue()).intValue());
                                    break;
                                case "maxBackoffSeconds":
                                    retryOptions.maxBackoffSeconds(((Number)option.getValue()).intValue());
                                    break;
                                case "maxDoublings":
                                    retryOptions.maxDoublings(((Number)option.getValue()).intValue());
                                    break;
                                default:
                                    throw new RuntimeException(option.getKey() + " is not a valid retry option parameter.");
                            }
                        }
                        options.retryOptions(retryOptions);
                    } else if (value instanceof RetryOptions) {
                        options.retryOptions((RetryOptions) value);
                    } else {
                        throw new RuntimeException("The retry options parameter should either be a map or an instance of RetryOptions.");
                    }
                    break;
                case "method":
                    if (value instanceof TaskOptions.Method) {
                        options = options.method((Method) value);
                    } else if(ALLOWED_METHODS.contains(value)) {
                        options = options.method(TaskOptions.Method.valueOf((String) value));
                    } else {
                        throw new RuntimeException("Not a valid method: " + value);
                    }
                    break;
                case "params":
                    if (value instanceof Map) {
                        for (Entry<String, Object> option : ((Map<String, Object>)value).entrySet()) {
                            options = options.param(option.getKey(), String.valueOf(option.getValue()));
                        }
                    } else {
                        throw new RuntimeException("The params key/value pairs should be passed as a map.");
                    }
                    break;
                   
                case "payload":
                    if (value instanceof List<?>) {
                        List<?> list = (List<?>) value;
                        options = options.payload(String.valueOf(list.get(0)), String.valueOf(list.get(1)));
                    } else if (value instanceof String) {
                        options = options.payload((String)value);
                    } else if (value instanceof Closure) {
                        options = options.payload(DefaultGroovyMethods.asType((Closure<?>)value, DeferredTask.class));
                    } else if (value instanceof DeferredTask) {
                        options = options.payload((DeferredTask)value);
                    } else {
                        options = options.payload(value.toString());
                    }
                    break;
                default:
                    throw new RuntimeException(key + " is not a valid task option.\n" +
                            "Allowed: countdownMillis, etaMillis, taskName, url, headers, methods, params and payload");
View Full Code Here

        Key deleteKey = KeyFactory.stringToKey(test);
        datastore.delete(deleteKey);
        break;
      case "deleteUserQueue" :
        Queue queue = QueueFactory.getDefaultQueue();
        TaskOptions task = TaskOptions.Builder.withUrl("/user?cmd=deleteUser&id=" + req.getParameter("id")).method(Method.DELETE);
        queue.add(task);
        break;
      default:
        throw new ServletException("Cette commande n'existe pas");
    }
View Full Code Here

    } catch (ParseException e) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST,e.getMessage());
    }
   
    Queue queue = QueueFactory.getDefaultQueue();
    TaskOptions task=TaskOptions.Builder.withUrl("/user")
      .param("cmd", "addUser")
      .param("nom", request.getParameter("nom"))
      .param("prenom", request.getParameter("prenom"))
      .param("dateNaissance", request.getParameter("dateNaissance"))
      .param("email", request.getParameter("email"))
View Full Code Here

    public static final String pLAST_ID = "LastId";
    private static final String pCHUNK_SIZE = "ChunkSize";

    public static TaskHandle submit(int chunkId, Key startKey, Key lastKey, int chunkSize) {
        Queue queue = TaskUtils.getQueue(ChunkedRuleProcessor.class);
        TaskOptions options = TaskUtils.newTaskOptions(ChunkedRuleProcessor.class)
            .param(pCHUNK_ID, Integer.toString(chunkId))
            .param(pSTART_ID, KeyFactory.keyToString(startKey))
            .param(pLAST_ID, KeyFactory.keyToString(lastKey))
            .param(pCHUNK_SIZE, Long.toString(chunkSize));
        TaskHandle handle = queue.add(options);
View Full Code Here

    @Test
    public void testTaskHandleContainsAllNecessaryProperties() throws Exception {
        String name = "testTaskHandleContainsAllNecessaryProperties-" + System.currentTimeMillis();
        Queue queue = QueueFactory.getDefaultQueue();

        TaskOptions options = withTaskName(name).payload("payload");
        options.etaMillis(0); // TODO -- remove this once NPE is fixewd

        TaskHandle handle = queue.add(options);

        assertEquals("default", handle.getQueueName());
        assertEquals(name, handle.getName());
View Full Code Here

    }

    @Test
    public void testExecQueue() {
        String testMethodTag = "testDefaultTag"// Each test tagged for DS entity.
        TaskOptions taskoptions = TaskOptions.Builder
            .withMethod(TaskOptions.Method.POST)
            .param(TEST_RUN_ID, testRunId// testRunId used to track test in DS.
            .param(TEST_METHOD_TAG, testMethodTag)
            .etaMillis(0);
View Full Code Here

TOP

Related Classes of com.google.appengine.api.taskqueue.TaskOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.