Skip to content

Commit 7561618

Browse files
committed
Merge branch 'tm_merge_conflict' into feature/taskmanager
2 parents ca990c0 + ce8e81e commit 7561618

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/com/github/bustedearlobes/themis/taskmanager/ScheduledTask.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public abstract class ScheduledTask extends ListenerAdapter implements Runnable,
2323
private long repeat;
2424
private long numberOfRuns;
2525
private AtomicBoolean isComplete;
26+
private AtomicBoolean isInProgress;
2627
private transient long timeOfNextRun;
2728
private transient JDA jda;
2829

@@ -39,7 +40,7 @@ protected boolean taskIsReady() {
3940
}
4041

4142
protected boolean isExpired() {
42-
return (numberOfRuns > repeat);
43+
return ((numberOfRuns > repeat) && isComplete());
4344
}
4445

4546
protected JDA getJDA() {
@@ -93,6 +94,7 @@ protected User getUserById(String userId) {
9394

9495
@Override
9596
public final void run() {
97+
isInProgress.set(true);
9698
jda.addEventListener(this);
9799
try {
98100
runTask();
@@ -131,4 +133,8 @@ public long getTimeUntilNextRun() {
131133
}
132134

133135
protected abstract void runTask();
136+
137+
public boolean isInProgress() {
138+
return isInProgress.get();
139+
}
134140
}

src/main/java/com/github/bustedearlobes/themis/taskmanager/TaskManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void run() {
6060
synchronized(scheduledTasks) {
6161
for(int i = 0; i < scheduledTasks.size(); i++) {
6262
task = scheduledTasks.get(i);
63-
if(task.taskIsReady()) {
63+
if(task.taskIsReady() && !task.isInProgress()) {
6464
executor.execute(task);
6565
task.incrementRun();
6666
}
@@ -86,9 +86,9 @@ public void run() {
8686
public void shutdown() {
8787
isRunning.set(false);
8888
executor.shutdown();
89-
LOG.info("Shutting down task manager. Awaiting 30 seconds max for safe task exit...");
89+
LOG.info("Shutting down task manager. Awaiting 5 seconds max for safe task exit...");
9090
try {
91-
if(!executor.awaitTermination(30, TimeUnit.SECONDS)) {
91+
if(!executor.awaitTermination(5, TimeUnit.SECONDS)) {
9292
LOG.warning("Could not shut down task manager safely. Timeout exceded");
9393
executor.shutdownNow();
9494
}

0 commit comments

Comments
 (0)