Search in sources :

Example 1 with JobManager

use of com.linkedin.thirdeye.datalayer.bao.JobManager in project pinot by linkedin.

the class DetectionJobScheduler method synchronousBackFill.

/**
   * Different from asynchronous backfill in runBackfill, it will return after the backfill is done.
   * This function monitors the backfill task status, and return once the tasks are completed.
   * @param functionId
   * the function id to be backfilled
   * @param backfillStartTime
   * the monitor start time for backfill
   * @param backfillEndTime
   * the monitor end time for backfill
   * @param force
   * set to false to resume from previous backfill if there exists any
   */
public void synchronousBackFill(long functionId, DateTime backfillStartTime, DateTime backfillEndTime, boolean force) {
    Long jobExecutionId = runBackfill(functionId, backfillStartTime, backfillEndTime, force);
    if (jobExecutionId == null) {
        LOG.warn("Unable to perform backfill on function Id {} between {} and {}", functionId, backfillStartTime, backfillEndTime);
        return;
    }
    TaskManager taskDAO = DAO_REGISTRY.getTaskDAO();
    JobManager jobDAO = DAO_REGISTRY.getJobDAO();
    JobDTO jobDTO = null;
    List<TaskDTO> scheduledTaskDTO = taskDAO.findByJobIdStatusNotIn(jobExecutionId, TaskConstants.TaskStatus.COMPLETED);
    int retryCounter = 0;
    while (scheduledTaskDTO.size() > 0) {
        boolean hasFailedTask = false;
        for (TaskDTO taskDTO : scheduledTaskDTO) {
            if (taskDTO.getStatus() == TaskConstants.TaskStatus.FAILED) {
                if (retryCounter >= MAX_BACKFILL_RETRY) {
                    LOG.warn("The backfill of anomaly function {} (task id: {}) failed. Stop retry.", functionId, jobExecutionId);
                    // Set job to be failed
                    jobDTO = jobDAO.findById(jobExecutionId);
                    if (jobDTO.getStatus() != JobConstants.JobStatus.FAILED) {
                        jobDTO.setStatus(JobConstants.JobStatus.FAILED);
                        jobDAO.save(jobDTO);
                    }
                    return;
                }
                hasFailedTask = true;
                LOG.warn("The backfill of anomaly function {} (task id: {}) failed. Retry count: {}", functionId, jobExecutionId, retryCounter);
            }
        }
        if (hasFailedTask) {
            retryCounter++;
            jobExecutionId = runBackfill(functionId, backfillStartTime, backfillEndTime, force);
        }
        try {
            TimeUnit.SECONDS.sleep(SYNC_SLEEP_SECONDS);
        } catch (InterruptedException e) {
            LOG.warn("The monitoring thread for anomaly function {} (task id: {}) backfill is awakened.", functionId, jobExecutionId);
        }
        scheduledTaskDTO = taskDAO.findByJobIdStatusNotIn(jobExecutionId, TaskConstants.TaskStatus.COMPLETED);
    }
    // Set job to be completed
    jobDTO = jobDAO.findById(jobExecutionId);
    if (jobDTO.getStatus() != JobConstants.JobStatus.COMPLETED) {
        jobDTO.setStatus(JobConstants.JobStatus.COMPLETED);
        jobDAO.save(jobDTO);
    }
}
Also used : JobDTO(com.linkedin.thirdeye.datalayer.dto.JobDTO) TaskManager(com.linkedin.thirdeye.datalayer.bao.TaskManager) JobManager(com.linkedin.thirdeye.datalayer.bao.JobManager) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO)

Aggregations

JobManager (com.linkedin.thirdeye.datalayer.bao.JobManager)1 TaskManager (com.linkedin.thirdeye.datalayer.bao.TaskManager)1 JobDTO (com.linkedin.thirdeye.datalayer.dto.JobDTO)1 TaskDTO (com.linkedin.thirdeye.datalayer.dto.TaskDTO)1