Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Solve #1701, Add one-shot rule support #1702

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public long getEvery() {
}

public boolean isOneShot() {
return startTime == endTime && every == 0;
return startTime == endTime && startTime == 0 && every == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ public ExecutorScheduler(int numThreads) {
public void addPeriodicityTask(RuleExecutor re) {
TimeBasedScheduleInfo si = re.getTranslateResult().getTbScheduleInfo();
long now = System.currentTimeMillis();
service.scheduleAtFixedRate(re, si.getStartTime() - now,
si.getEvery(), TimeUnit.MILLISECONDS);
long startDelay = si.getStartTime() - now;
if (startDelay < 0) {
startDelay = 0;
}
long every = si.getEvery();
if (every <= 0) {
every = 5000;
}
service.scheduleAtFixedRate(re, startDelay, every, TimeUnit.MILLISECONDS);
}

public void addPeriodicityTask(ScheduleInfo schInfo, Runnable work) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ public void run() {
TimeBasedScheduleInfo scheduleInfo = tr.getTbScheduleInfo();

if (scheduleInfo.getEndTime() != TimeBasedScheduleInfo.FOR_EVER
// TODO: tricky here, time passed
&& !scheduleInfo.isOneShot()
&& 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, System.currentTimeMillis(), 0, 0);
exitSchedule();
Expand All @@ -288,12 +287,8 @@ public void run() {
numCmdSubmitted = submitCmdlets(info, files);
}
ruleManager.updateRuleInfo(rid, null, System.currentTimeMillis(), 1, numCmdSubmitted);
if (exited) {
exitSchedule();
}
// System.out.println(this + " -> " + System.currentTimeMillis());
long endProcessTime = System.currentTimeMillis();

long endProcessTime = System.currentTimeMillis();
if (endProcessTime - startCheckTime > 2000 || LOG.isDebugEnabled()) {
LOG.warn(
"Rule "
Expand All @@ -309,6 +304,14 @@ public void run() {
+ ".");
}

if (scheduleInfo.isOneShot()) {
ruleManager.updateRuleInfo(rid, RuleState.FINISHED, System.currentTimeMillis(), 0, 0);
exitSchedule();
}

if (exited) {
exitSchedule();
}
} catch (IOException e) {
LOG.error("Rule " + ctx.getRuleId() + " exception", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trigger
: AT timepointexpr #triTimePoint
| EVERY timeintvalexpr duringexpr? #triCycle
| ON fileEvent duringexpr? #triFileEvent
| ONCE #triOnce
;

duringexpr : FROM timepointexpr (TO timepointexpr)? ;
Expand Down Expand Up @@ -175,6 +176,7 @@ AND : 'and' ;
EVERY : 'every' ;
FROM : 'from' ;
ON : 'on' ;
ONCE : 'once' ;
OR : 'or' ;
NOW : 'now' ;
NOT : 'not' ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public TreeNode visitConditions(SmartRuleParser.ConditionsContext ctx) {
return conditions;
}

@Override
public TreeNode visitTriOnce(SmartRuleParser.TriOnceContext ctx) {
timeBasedScheduleInfo = new TimeBasedScheduleInfo();
return null;
}

@Override
public TreeNode visitTriTimePoint(SmartRuleParser.TriTimePointContext ctx) {
timeBasedScheduleInfo = new TimeBasedScheduleInfo();
Expand Down