Skip to content

Commit

Permalink
fix that task gets inserted multiple times into unfinishedTasks (#4)
Browse files Browse the repository at this point in the history
* fix that task gets inserted multiple times into unfinishedTasks

* State now has a level, changeStateOfTask() will never decrease Task State level

* removed proposed check in onPodTermination(), fixed formatting

* task state change is not a warning, changed to log.debug; fixed unneccessary reformatting at onPodTermination

---------

Co-authored-by: Florian Friederici <[email protected]>
  • Loading branch information
friederici and Florian Friederici authored Oct 26, 2023
1 parent 15f8ac9 commit f968cb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/main/java/cws/k8s/scheduler/model/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

public enum State {

RECEIVED_CONFIG, UNSCHEDULED, SCHEDULED, PREPARED, ERROR, PROCESSING_FINISHED, FINISHED, FINISHED_WITH_ERROR, INIT_WITH_ERRORS, DELETED
RECEIVED_CONFIG(0), UNSCHEDULED(1), SCHEDULED(2), PREPARED(3), INIT_WITH_ERRORS(3), PROCESSING_FINISHED(4),
FINISHED(5), FINISHED_WITH_ERROR(5), ERROR(1000), DELETED(Integer.MAX_VALUE);

public final int level;

State(int level) {
this.level = level;
}

}
14 changes: 8 additions & 6 deletions src/main/java/cws/k8s/scheduler/scheduler/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,16 @@ public void endBatch( int tasksInBatch ){
/**
* @return returns the task, if the state was changed
*/
Task changeStateOfTask(Pod pod, State state){
Task t = getTaskByPod( pod );
if( t != null ){
synchronized ( t.getState() ){
if( t.getState().getState() != state ){
t.getState().setState( state );
Task changeStateOfTask(Pod pod, State state) {
Task t = getTaskByPod(pod);
if (t != null) {
synchronized (t.getState()) {
if (t.getState().getState().level < state.level) {
t.getState().setState(state);
return t;
} else {
log.debug("Task {} was already in state {} and cannot be changed to {}", t.getConfig().getRunName(),
t.getState().getState(), state);
return null;
}
}
Expand Down

0 comments on commit f968cb5

Please sign in to comment.