Ejemplo n.º 1
0
  @Override
  public void addTask(Task task) {
    Queue queue = null;

    logger.info("Adding Task[" + task.toString() + "]");

    if (task.getQueueName() == null
        || (task.getQueueName() != null && task.getQueueName().trim().length() == 0)) {
      queue = QueueFactory.getDefaultQueue();
    } else {
      queue = QueueFactory.getQueue(task.getQueueName());
    }

    logger.info("Queue to be used : " + queue.getQueueName());

    if (task.getParameterName() != null && task.getParameterValue() != null) {
      logger.info("Adding Parameters to process");
      queue.add(
          TaskOptions.Builder.withUrl(task.getEndpoint())
              .param(task.getParameterName(), task.getParameterValue())
              .taskName(task.getName()));
    } else {
      logger.info("excluding Parameters to process");
      queue.add(TaskOptions.Builder.withUrl(task.getEndpoint()).taskName(task.getName()));
    }
  }
Ejemplo n.º 2
0
 public static void createCatalogBackendTask(String queueName, Date date) {
   Queue queue = QueueFactory.getQueue(queueName);
   TaskOptions taskOptions =
       TaskOptions.Builder.withUrl("/tasks/catalog").method(TaskOptions.Method.POST);
   if (date != null) {
     taskOptions.param(
         "date", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date));
   }
   taskOptions.param("backend", Boolean.toString(true));
   queue.add(taskOptions);
 }
 /**
  * puts the summarization request into the queue
  *
  * @param request
  */
 private void invokeSummarizer(DataSummarizationRequest request) {
   Queue queue = QueueFactory.getQueue(queueName);
   queue.add(
       TaskOptions.Builder.withUrl(summarizerPath)
           .param(DataSummarizationRequest.ACTION_PARAM, request.getAction())
           .param(DataSummarizationRequest.OBJECT_KEY, request.getObjectKey())
           .param(DataSummarizationRequest.OBJECT_TYPE, request.getType())
           .param(DataSummarizationRequest.OFFSET_KEY, request.getOffset().toString())
           .param(
               DataSummarizationRequest.CURSOR_PARAM,
               request.getCursor() != null ? request.getCursor() : ""));
 }
Ejemplo n.º 4
0
 public static void createInitBackendTask(String queueName, Cursor cursor) {
   Queue queue = QueueFactory.getQueue(queueName);
   TaskOptions taskOptions =
       TaskOptions.Builder.withUrl("/tasks/init").method(TaskOptions.Method.POST);
   if (cursor != null && cursor.getElement() != null && cursor.getOffset() != null) {
     taskOptions
         .param("element", cursor.getElement())
         .param("offset", cursor.getOffset().toString());
   }
   if (cursor != null && cursor.backend) {
     taskOptions.param("backend", Boolean.toString(cursor.backend));
   }
   log.info("Added queue " + taskOptions.toString());
   queue.add(taskOptions);
 }
Ejemplo n.º 5
0
  /**
   * handles the callback from the device indicating that a new data file is available. This method
   * will call processFile to retrieve the file and persist the data to the data store it will then
   * add access points for each water point in the survey responses.
   *
   * @param req
   */
  @SuppressWarnings("rawtypes")
  private void ingestFile(TaskRequest req) {
    if (req.getFileName() != null) {
      log.info("	Task->processFile");
      ArrayList<SurveyInstance> surveyInstances =
          processFile(req.getFileName(), req.getPhoneNumber(), req.getChecksum(), req.getOffset());
      Map<Long, Survey> surveyMap = new HashMap<Long, Survey>();
      SurveyDAO surveyDao = new SurveyDAO();
      Queue summQueue = QueueFactory.getQueue("dataSummarization");
      Queue defaultQueue = QueueFactory.getDefaultQueue();
      for (SurveyInstance instance : surveyInstances) {
        Survey s = surveyMap.get(instance.getSurveyId());
        if (s == null) {
          s = surveyDao.getById(instance.getSurveyId());
          surveyMap.put(instance.getSurveyId(), s);
        }
        if (s != null && s.getRequireApproval() != null && s.getRequireApproval()) {
          // if the survey requires approval, don't run any of the
          // processors
          instance.setApprovedFlag("False");
          continue;
        } else {
          ProcessingAction pa = dispatch(instance.getKey().getId() + "");
          TaskOptions options = TaskOptions.Builder.withUrl(pa.getDispatchURL());
          Iterator it = pa.getParams().keySet().iterator();
          while (it.hasNext()) {
            options.param("key", (String) it.next());
          }
          log.info(
              "Received Task Queue calls for surveyInstanceKey: " + instance.getKey().getId() + "");
          aph.processSurveyInstance(instance.getKey().getId() + "");
          summQueue.add(
              TaskOptions.Builder.withUrl("/app_worker/datasummarization")
                  .param("objectKey", instance.getKey().getId() + "")
                  .param("type", "SurveyInstance"));
          // process the "new" domain structure

          defaultQueue.add(
              TaskOptions.Builder.withUrl("/app_worker/surveyalservlet")
                  .param(
                      SurveyalRestRequest.ACTION_PARAM, SurveyalRestRequest.INGEST_INSTANCE_ACTION)
                  .param(
                      SurveyalRestRequest.SURVEY_INSTANCE_PARAM, instance.getKey().getId() + ""));
        }
      }
    }
  }
  @GET
  @Path("/monitoring/check-for-updates")
  public void execute() throws Exception {
    TaskOptions taskOptions;
    Queue queue = QueueFactory.getQueue("monitoring");

    for (Monitoring monitoring : MonitoringManager.findAll()) {
      if (!monitoring.isCompleted()) {
        taskOptions = Builder.withUrl("/admin/monitoring/check-for-updates");
        taskOptions = taskOptions.param("clientId", monitoring.getClientId());
        taskOptions = taskOptions.param("trackId", monitoring.getTrackId());
        taskOptions.method(POST);

        queue.add(taskOptions);
      }
    }
  }
Ejemplo n.º 7
0
 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
   Queue queue = QueueFactory.getQueue("pesky-slow");
   queue.add(withUrl("/cron/basketballscrape"));
 }
Ejemplo n.º 8
0
 public void enqueue(String queueName) {
   // the named queue runs on the foreground thread...
   Queue queue = QueueFactory.getQueue(queueName);
   queue.add(task);
 }