Package com.dianping.cat.core.dal

Examples of com.dianping.cat.core.dal.Task


  @Override
  public void run() {
    String localIp = getLoaclIp();
    while (running) {
      try {
        Task task = findDoingTask(localIp);
        if (task == null) {
          task = findTodoTask();
        }

        boolean again = false;
        if (task != null) {
          try {
            task.setConsumer(localIp);
            if (task.getStatus() == TaskConsumer.STATUS_DOING || updateTodoToDoing(task)) {
              int retryTimes = 0;
              while (!processTask(task)) {
                retryTimes++;
                if (retryTimes < MAX_TODO_RETRY_TIMES) {
                  taskRetryDuration();
                } else {
                  updateDoingToFailure(task);
                  again = true;
                  break;
                }
              }
              if (!again) {
                updateDoingToDone(task);
              }
            }
          } catch (Throwable e) {
            Cat.logError(task.toString(), e);
          }
        } else {
          taskNotFoundDuration();
        }
      } catch (Throwable e) {
View Full Code Here


  @Inject
  private TaskDao m_taskDao;

  @Override
  protected Task findDoingTask(String ip) {
    Task task = null;
    try {
      task = m_taskDao.findByStatusConsumer(STATUS_DOING, ip, TaskEntity.READSET_FULL);
    } catch (DalException e) {
    }
    return task;
View Full Code Here

    return task;
  }

  @Override
  protected Task findTodoTask() {
    Task task = null;
    try {
      task = m_taskDao.findByStatusConsumer(STATUS_TODO, null, TaskEntity.READSET_FULL);
    } catch (DalException e) {
    }
    return task;
View Full Code Here

   *
   * @throws InterruptedException
   */
  @Test
  public void testContinueDoingTaskSuccess() throws InterruptedException {
    final Task t = new Task();
    t.setStatus(TaskConsumer.STATUS_DOING);

    final List<Task> taskList = new ArrayList<Task>();
    taskList.add(t);

    TaskConsumerWrap consumer = new TaskConsumerWrap() {
      @Override
      protected Task findDoingTask(String ip) {
        super.findDoingTask(ip);
        return taskList.size() == 0 ? null : taskList.remove(0);
      }

      @Override
      protected boolean processTask(Task doing) {
        super.processTask(doing);
        return true;
      }

      @Override
      protected boolean updateDoingToDone(Task doing) {
        super.updateDoingToDone(doing);
        doing.setStatus(STATUS_DONE);
        return true;
      }

    };

    new Thread(consumer).start();
    while (!consumer.isStopped()) {
      Thread.sleep(10);
    }

    String expectValue = Arrays.toString(consumer.replayer.toArray());

    Assert.assertEquals("[1, 10, 3, 1, 8, 4]", expectValue);

    Assert.assertEquals(TaskConsumer.STATUS_DONE, t.getStatus());

  }
View Full Code Here

   *
   * @throws InterruptedException
   */
  @Test
  public void testContinueDoingTaskFail() throws InterruptedException {
    final Task t = new Task();
    t.setStatus(TaskConsumer.STATUS_DOING);

    final List<Task> taskList = new ArrayList<Task>();
    taskList.add(t);

    TaskConsumerWrap consumer = new TaskConsumerWrap() {
      @Override
      protected Task findDoingTask(String ip) {
        super.findDoingTask(ip);
        return taskList.size() == 0 ? null : taskList.remove(0);
      }

    };

    new Thread(consumer).start();
    while (!consumer.isStopped()) {
      Thread.sleep(10);
    }

    Assert.assertEquals("[1, 10, 5, 1, 8, 4]", Arrays.toString(consumer.replayer.toArray()));
    Assert.assertEquals(TaskConsumer.STATUS_DOING, t.getStatus());
  }
View Full Code Here

   *
   * @throws InterruptedException
   */
  @Test
  public void testTodoTaskSuccess() throws InterruptedException {
    final Task t = new Task();
    t.setStatus(TaskConsumer.STATUS_TODO);

    final List<Task> taskList = new ArrayList<Task>();
    taskList.add(t);

    final TaskConsumerWrap consumer = new TaskConsumerWrap() {

      @Override
      protected boolean updateTodoToDoing(Task todo) {
        super.updateTodoToDoing(todo);
        return true;
      }

      @Override
      protected boolean processTask(Task doing) {
        super.processTask(doing);
        return true;
      }

      @Override
      protected boolean updateDoingToDone(Task doing) {
        super.updateDoingToDone(doing);
        t.setStatus(TaskConsumer.STATUS_DONE);
        return true;
      }

      @Override
      protected Task findTodoTask() {
        super.findTodoTask();
        return taskList.size() == 0 ? null : taskList.remove(0);
      }

    };

    new Thread(consumer).start();
    while (!consumer.isStopped()) {
      Thread.sleep(10);
    }

    Assert.assertEquals("[1, 8, 7, 10, 3, 1, 8, 4]", Arrays.toString(consumer.replayer.toArray()));
    Assert.assertEquals(TaskConsumer.STATUS_DONE, t.getStatus());
  }
View Full Code Here

   *
   * @throws InterruptedException
   */
  @Test
  public void testTodoTaskFail() throws InterruptedException {
    final Task t = new Task();
    t.setStatus(TaskConsumer.STATUS_TODO);

    final List<Task> taskList = new ArrayList<Task>();
    taskList.add(t);

    final TaskConsumerWrap consumer = new TaskConsumerWrap() {

      @Override
      protected boolean updateTodoToDoing(Task todo) {
        super.updateTodoToDoing(todo);
        return true;
      }

      @Override
      protected Task findTodoTask() {
        super.findTodoTask();
        return taskList.size() == 0 ? null : taskList.remove(0);
      }

      @Override
      protected boolean updateDoingToFailure(Task todo) {
        super.updateDoingToFailure(todo);
        todo.setStatus(STATUS_FAIL);
        return true;
      }

    };

    new Thread(consumer).start();
    while (!consumer.isStopped()) {
      Thread.sleep(10);
    }

    Assert.assertEquals("[1, 8, 7, 10, 5, 1, 8, 4]", Arrays.toString(consumer.replayer.toArray()));
    Assert.assertEquals(TaskConsumer.STATUS_FAIL, t.getStatus());
  }
View Full Code Here

  public String day4 = "2014-07-28";

  @Test
  public void test() throws Exception {
    ReportFacade reportFacade = (ReportFacade) lookup(ReportFacade.class);
    Task task = new Task();
    Date reportPeriod = new SimpleDateFormat("yyyy-MM-dd").parse(day3);

    task.setReportName(Constants.REPORT_ROUTER);
    task.setReportPeriod(reportPeriod);
    task.setReportDomain(Constants.CAT);
    task.setTaskType(1);
    reportFacade.builderReport(task);

    task.setReportPeriod(new SimpleDateFormat("yyyy-MM-dd").parse(day4));
    reportFacade.builderReport(task);
  }
View Full Code Here

  private void createMonthlyTask(Date period, String domain, String name) throws DalException {
    createTask(period, domain, name, ReportType.MONTH);
  }

  protected void createTask(Date period, String domain, String name, int reportType) throws DalException {
    Task task = m_taskDao.createLocal();

    task.setCreationDate(new Date());
    task.setProducer(m_ip);
    task.setReportDomain(domain);
    task.setReportName(name);
    task.setReportPeriod(period);
    task.setStatus(STATUS_TODO);
    task.setTaskType(reportType);
    m_taskDao.insert(task);
  }
View Full Code Here

TOP

Related Classes of com.dianping.cat.core.dal.Task

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.