diff --git a/.github/workflows/boot.yml b/.github/workflows/boot.yml index 1f8cea54..e488bd5d 100644 --- a/.github/workflows/boot.yml +++ b/.github/workflows/boot.yml @@ -1,5 +1,5 @@ name: spring-boot-compatibility -on: [push, pull_request] +on: [push] jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8334c69b..98a94391 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: build -on: [push, pull_request] +on: [push] jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..d09ad74d --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,23 @@ +name: pull-request-check +on: [pull_request] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ '17' ] + name: Temurin ${{ matrix.java }} + steps: + - uses: actions/checkout@v3 + + - name: Set up Java ${{ matrix.java }} + uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + cache: 'maven' + + - name: Run all tests + run: mvn -B spotless:check + env: + TZ: UTC diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/FailureHandler.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/FailureHandler.java index 8553f689..e4cba3aa 100644 --- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/FailureHandler.java +++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/FailureHandler.java @@ -52,9 +52,10 @@ public void onFailure( round( sleepDuration.toMillis() * pow(exponentialRate, executionComplete.getExecution().consecutiveFailures)); - Instant nextTry = Instant.now().plusMillis(retryDurationMs); + Instant nextTry = executionComplete.getTimeDone().plusMillis(retryDurationMs); LOG.debug( - "Execution failed. Retrying task {} at {}", + "Execution failed {}. Retrying task {} at {}", + executionComplete.getTimeDone(), executionComplete.getExecution().taskInstance, nextTry); executionOperations.reschedule(executionComplete, nextTry); @@ -101,7 +102,7 @@ public OnFailureRetryLater(Duration sleepDuration) { @Override public void onFailure( ExecutionComplete executionComplete, ExecutionOperations executionOperations) { - Instant nextTry = Instant.now().plus(sleepDuration); + Instant nextTry = executionComplete.getTimeDone().plus(sleepDuration); LOG.debug( "Execution failed. Retrying task {} at {}", executionComplete.getExecution().taskInstance, diff --git a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/SchedulerTest.java b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/SchedulerTest.java index 8b1a7359..d2197d41 100644 --- a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/SchedulerTest.java +++ b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/SchedulerTest.java @@ -262,7 +262,7 @@ public void should_reschedule_failure_on_exponential_backoff_with_default_rate() scheduler.executeDue(); // Simulate 30 minutes worth of time to validate we did not process more than we should - for (int minuteWorthOfTime = 1; minuteWorthOfTime <= 30; minuteWorthOfTime++) { + for (int minuteWorthOfTime = 1; minuteWorthOfTime <= 80; minuteWorthOfTime++) { clock.set(clock.now().plus(ofMinutes(1))); scheduler.executeDue(); } @@ -278,10 +278,10 @@ public void should_reschedule_failure_on_exponential_backoff_with_default_rate() Duration actualExponentialBackoffDuration = ofMillis(retryDurationMs); assertThat( scheduleTimeDifferenceFromFirstCall.getSeconds(), - greaterThanOrEqualTo(expectedSleepDuration.getSeconds())); + greaterThanOrEqualTo(expectedSleepDuration.minusSeconds(1).getSeconds())); assertThat( scheduleTimeDifferenceFromFirstCall.getSeconds(), - is(actualExponentialBackoffDuration.getSeconds())); + greaterThanOrEqualTo(actualExponentialBackoffDuration.minusSeconds(1).getSeconds())); } } @@ -312,7 +312,7 @@ public void should_reschedule_failure_on_exponential_backoff_with_defined_rate() scheduler.executeDue(); // Simulate 30 minutes worth of time to validate we did not process more than we should - for (int minuteWorthOfTime = 1; minuteWorthOfTime <= 30; minuteWorthOfTime++) { + for (int minuteWorthOfTime = 1; minuteWorthOfTime <= 80; minuteWorthOfTime++) { clock.set(clock.now().plus(ofMinutes(1))); scheduler.executeDue(); } @@ -320,19 +320,21 @@ public void should_reschedule_failure_on_exponential_backoff_with_defined_rate() assertThat(executionTimes.size(), is(10)); // Skip first execution of this b/c it was not using the exponential backoff but the first // attempted call before failure + Duration lastScheduleTimeDifferenceFromFirstCall = ZERO; for (int i = 1, executionTimesSize = executionTimes.size(); i < executionTimesSize; i++) { final Instant executionTime = executionTimes.get(i); long retryDurationMs = Math.round(expectedSleepDuration.toMillis() * Math.pow(customRate, i - 1)); - Duration scheduleTimeDifferenceFromFirstCall = between(firstExecution, executionTime); - Duration actualExponentialBackoffDuration = ofMillis(retryDurationMs); + Duration expectedTimeDifferenceFromFirstCall = + ofMillis(retryDurationMs).plus(lastScheduleTimeDifferenceFromFirstCall); + lastScheduleTimeDifferenceFromFirstCall = between(firstExecution, executionTime); assertThat( - scheduleTimeDifferenceFromFirstCall.getSeconds(), - greaterThanOrEqualTo(expectedSleepDuration.getSeconds())); + lastScheduleTimeDifferenceFromFirstCall.getSeconds(), + greaterThanOrEqualTo(expectedSleepDuration.minusSeconds(1).getSeconds())); assertThat( - scheduleTimeDifferenceFromFirstCall.getSeconds(), - is(actualExponentialBackoffDuration.getSeconds())); + lastScheduleTimeDifferenceFromFirstCall.getSeconds(), + greaterThanOrEqualTo(expectedTimeDifferenceFromFirstCall.minusSeconds(1).getSeconds())); } } }