Skip to content

feature: improvements on reschedule #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2021
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 @@ -152,7 +152,7 @@ public void close() {
}
}

private void executeBufferedEvents(String customResourceUid) {
private boolean executeBufferedEvents(String customResourceUid) {
boolean newEventForResourceId = eventBuffer.containsEvents(customResourceUid);
boolean controllerUnderExecution = isControllerUnderExecution(customResourceUid);
Optional<CustomResource> latestCustomResource =
Expand All @@ -167,6 +167,7 @@ private void executeBufferedEvents(String customResourceUid) {
retryInfo(customResourceUid));
log.debug("Executing events for custom resource. Scope: {}", executionScope);
executor.execute(new ControllerExecution(executionScope));
return true;
} else {
log.debug(
"Skipping executing controller for resource id: {}. Events in queue: {}."
Expand All @@ -175,6 +176,7 @@ private void executeBufferedEvents(String customResourceUid) {
newEventForResourceId,
controllerUnderExecution,
latestCustomResource.isPresent());
return false;
}
}

Expand Down Expand Up @@ -211,8 +213,10 @@ void eventProcessingFinished(
cleanupAfterDeletedEvent(executionScope.getCustomResourceUid());
} else {
cacheUpdatedResourceIfChanged(executionScope, postExecutionControl);
reScheduleExecutionIfInstructed(postExecutionControl, executionScope.getCustomResource());
executeBufferedEvents(executionScope.getCustomResourceUid());
var executed = executeBufferedEvents(executionScope.getCustomResourceUid());
if (!executed) {
reScheduleExecutionIfInstructed(postExecutionControl, executionScope.getCustomResource());
}
}
} finally {
lock.unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ public void scheduleTimedEventIfInstructedByPostExecutionControl() {
.scheduleOnce(any(), eq(testDelay));
}

@Test
public void reScheduleOnlyIfNotExecutedBufferedEvents() {
var testDelay = 10000l;
when(eventDispatcherMock.handleExecution(any()))
.thenReturn(PostExecutionControl.defaultDispatch().withReSchedule(testDelay));

defaultEventHandler.handleEvent(prepareCREvent());
defaultEventHandler.handleEvent(prepareCREvent());

verify(retryTimerEventSourceMock, timeout(SEPARATE_EXECUTION_TIMEOUT).times(0))
.scheduleOnce(any(), eq(testDelay));
}

@Test
public void doNotFireEventsIfClosing() {
defaultEventHandler.close();
Expand Down
2 changes: 1 addition & 1 deletion samples/common/crd/test_object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
name: custom-service1
spec:
name: testservice1
label: testlabel
label: testlabel