Search in sources :

Example 1 with ScheduleCron

use of com.dtstack.taier.develop.parser.ScheduleCron in project Taier by DTStack.

the class BatchTaskBatchVO method parsePeriodType.

public void parsePeriodType() {
    if (StringUtils.isNotBlank(this.getScheduleConf())) {
        try {
            ScheduleCron cron = ScheduleFactory.parseFromJson(this.getScheduleConf());
            this.setPeriodType(cron.getPeriodType());
        } catch (Exception e) {
            LOG.error("", e);
        }
    }
}
Also used : ScheduleCron(com.dtstack.taier.develop.parser.ScheduleCron)

Example 2 with ScheduleCron

use of com.dtstack.taier.develop.parser.ScheduleCron in project Taier by DTStack.

the class BatchTaskBatchVO method init.

private void init() {
    if (StringUtils.isNotBlank(this.getScheduleConf())) {
        try {
            ScheduleCron cron = ScheduleFactory.parseFromJson(this.getScheduleConf());
            this.cron = cron.getCronStr();
            this.taskPeriodId = cron.getPeriodType();
            if (ESchedulePeriodType.MIN.getVal() == cron.getPeriodType()) {
                taskPeriodType = "分钟任务";
            } else if (ESchedulePeriodType.HOUR.getVal() == cron.getPeriodType()) {
                taskPeriodType = "小时任务";
            } else if (ESchedulePeriodType.DAY.getVal() == cron.getPeriodType()) {
                taskPeriodType = "天任务";
            } else if (ESchedulePeriodType.WEEK.getVal() == cron.getPeriodType()) {
                taskPeriodType = "周任务";
            } else if (ESchedulePeriodType.MONTH.getVal() == cron.getPeriodType()) {
                taskPeriodType = "月任务";
            } else if (ESchedulePeriodType.CRON.getVal() == cron.getPeriodType()) {
                taskPeriodType = "自定义任务";
            }
        } catch (Exception e) {
            LOG.error("", e);
        }
    }
}
Also used : ScheduleCron(com.dtstack.taier.develop.parser.ScheduleCron)

Example 3 with ScheduleCron

use of com.dtstack.taier.develop.parser.ScheduleCron in project Taier by DTStack.

the class BatchTaskService method initTaskInfo.

/**
 *初始化 task的一些基本属性
 *
 * @param task
 * @return
 */
private boolean initTaskInfo(BatchTaskBatchVO task) {
    if (StringUtils.isBlank(task.getTaskDesc())) {
        task.setTaskDesc("");
    }
    if (StringUtils.isBlank(task.getTaskParams())) {
        task.setTaskParams("");
    }
    if (StringUtils.isBlank(task.getMainClass())) {
        task.setMainClass("");
    }
    if (StringUtils.isBlank(task.getScheduleConf())) {
        task.setScheduleConf(DEFAULT_SCHEDULE_CONF);
    } else {
        final JSONObject scheduleConf = JSON.parseObject(task.getScheduleConf());
        final String beginDate = scheduleConf.getString("beginDate");
        if (StringUtils.isBlank(beginDate) || "null".equalsIgnoreCase(beginDate)) {
            throw new RdosDefineException("生效日期起至时间不能为空");
        }
        final String endDate = scheduleConf.getString("endDate");
        if (StringUtils.isBlank(endDate) || "null".equalsIgnoreCase(endDate)) {
            throw new RdosDefineException("生效日期结束时间不能为空");
        }
    }
    if (task.getVersion() == null) {
        task.setVersion(0);
    }
    if (task.getCreateUserId() == null) {
        task.setCreateUserId(task.getUserId());
    }
    task.setGmtCreate(task.getGmtModified());
    // 增加注释
    task.setSqlText(this.createAnnotationText(task));
    task.setSubmitStatus(ESubmitStatus.UNSUBMIT.getStatus());
    task.setTaskParams(getDefaultTaskParam(task.getTenantId(), task.getTaskType()));
    task.setScheduleStatus(EScheduleStatus.NORMAL.getVal());
    task.setPeriodType(DEFAULT_SCHEDULE_PERIOD);
    String scConf = DEFAULT_SCHEDULE_CONF;
    int period = DEFAULT_SCHEDULE_PERIOD;
    if (task.getFlowId() != null && task.getFlowId() > 0) {
        final BatchTask flow = this.developTaskDao.getOne(task.getFlowId());
        if (flow != null) {
            scConf = flow.getScheduleConf();
            final ScheduleCron scheduleCron;
            try {
                scheduleCron = ScheduleFactory.parseFromJson(scConf);
            } catch (Exception e) {
                throw new RdosDefineException(e.getMessage(), e);
            }
            period = scheduleCron.getPeriodType();
        }
        task.setScheduleConf(scConf);
    }
    task.setPeriodType(period);
    if (Objects.isNull(task.getFlowId())) {
        task.setFlowId(0L);
    }
    return true;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) ScheduleCron(com.dtstack.taier.develop.parser.ScheduleCron) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IOException(java.io.IOException) DtCenterDefException(com.dtstack.taier.common.exception.DtCenterDefException)

Aggregations

ScheduleCron (com.dtstack.taier.develop.parser.ScheduleCron)3 JSONObject (com.alibaba.fastjson.JSONObject)1 DtCenterDefException (com.dtstack.taier.common.exception.DtCenterDefException)1 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 BatchTask (com.dtstack.taier.dao.domain.BatchTask)1 IOException (java.io.IOException)1