Skip to content

Commit

Permalink
Merge pull request #3274 from arunans23/task
Browse files Browse the repository at this point in the history
Improve NTaskTaskManager to remove pending tasks during server startup
  • Loading branch information
arunans23 authored Mar 20, 2024
2 parents a53f9e5 + 1b13978 commit c91e6bd
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ public boolean reschedule(String taskName, TaskDescription taskDescription) {

@Override
public boolean delete(String taskName) {
if (!isInitialized()) {
return false;
}
if (taskName == null) {
return false;
}
Expand All @@ -172,6 +169,10 @@ public boolean delete(String taskName) {
try {
boolean deleted;
synchronized (lock) {
if (!isInitialized()) {
checkAndDeleteTaskFromQueue(name, group, taskName);
return false;
}
if (taskManager == null) {
logger.warn("#delete Could not delete task [" + taskName + "]. Task manager is not available.");
return false;
Expand Down Expand Up @@ -714,5 +715,18 @@ public void run() {
}).start();
}

}
private void checkAndDeleteTaskFromQueue(String name, String group, String taskName) {
synchronized (taskQueueLock) {
Iterator<TaskDescription> iterator = taskQueue.iterator();
while (iterator.hasNext()) {
TaskDescription taskDescription = iterator.next();
if (taskDescription.getName().equals(name) && taskDescription.getTaskGroup().equals(group)) {
iterator.remove();
NTaskAdapter.removeProperty(taskName);
logger.info("Deleted queued task [" + name + "::" + group + "].");
}
}
}
}

}

0 comments on commit c91e6bd

Please sign in to comment.