Search in sources :

Example 1 with TimeBasedScheduleInfo

use of org.smartdata.server.rule.parser.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class RuleQueryExecutor method run.

@Override
public void run() {
    if (exited) {
        exitSchedule();
    }
    long rid = ctx.getRuleId();
    try {
        long startCheckTime = System.currentTimeMillis();
        if (ruleManager.isClosed()) {
            exitSchedule();
        }
        RuleInfo info = ruleManager.getRuleInfo(rid);
        RuleState state = info.getState();
        if (exited || state == RuleState.DELETED || state == RuleState.FINISHED || state == RuleState.DISABLED) {
            exitSchedule();
        }
        TimeBasedScheduleInfo scheduleInfo = tr.getTbScheduleInfo();
        if (scheduleInfo.getEndTime() != TimeBasedScheduleInfo.FOR_EVER && // TODO: tricky here, time passed
        startCheckTime - scheduleInfo.getEndTime() > 0) {
            // TODO: special for scheduleInfo.isOneShot()
            LOG.info("Rule " + ctx.getRuleId() + " exit rule executor due to time passed or finished");
            ruleManager.updateRuleInfo(rid, RuleState.FINISHED, timeNow(), 0, 0);
            exitSchedule();
        }
        List<String> files = executeFileRuleQuery();
        long endCheckTime = System.currentTimeMillis();
        int numCmdSubmitted = submitCommands(files, rid);
        ruleManager.updateRuleInfo(rid, null, timeNow(), 1, numCmdSubmitted);
        if (exited) {
            exitSchedule();
        }
        //System.out.println(this + " -> " + System.currentTimeMillis());
        long endProcessTime = System.currentTimeMillis();
        if (endProcessTime - startCheckTime > 3000 || LOG.isDebugEnabled()) {
            LOG.warn("Rule " + ctx.getRuleId() + " execution took " + (endProcessTime - startCheckTime) + "ms. QueryTime = " + (endCheckTime - startCheckTime) + "ms, SubmitTime = " + (endProcessTime - endCheckTime) + "ms.");
        }
    } catch (IOException e) {
        LOG.error("Rule " + ctx.getRuleId() + " exception", e);
    }
}
Also used : RuleState(org.smartdata.common.rule.RuleState) IOException(java.io.IOException) RuleInfo(org.smartdata.common.rule.RuleInfo) TimeBasedScheduleInfo(org.smartdata.server.rule.parser.TimeBasedScheduleInfo)

Example 2 with TimeBasedScheduleInfo

use of org.smartdata.server.rule.parser.TimeBasedScheduleInfo in project SSM by Intel-bigdata.

the class ExecutorScheduler method addPeriodicityTask.

public void addPeriodicityTask(RuleQueryExecutor re) {
    TimeBasedScheduleInfo si = re.getTranslateResult().getTbScheduleInfo();
    long now = System.currentTimeMillis();
    service.scheduleAtFixedRate(re, si.getStartTime() - now, si.getEvery(), TimeUnit.MILLISECONDS);
}
Also used : TimeBasedScheduleInfo(org.smartdata.server.rule.parser.TimeBasedScheduleInfo)

Aggregations

TimeBasedScheduleInfo (org.smartdata.server.rule.parser.TimeBasedScheduleInfo)2 IOException (java.io.IOException)1 RuleInfo (org.smartdata.common.rule.RuleInfo)1 RuleState (org.smartdata.common.rule.RuleState)1