-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retry in parameter in the Throttling exception, and take into acc…
…ount last execution duration
- Loading branch information
1 parent
8dd3177
commit 52ba96e
Showing
7 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...in/java/com/cp/compiler/services/businesslogic/strategies/ExecutionStrategyDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.cp.compiler.services.businesslogic.strategies; | ||
|
||
import com.cp.compiler.executions.Execution; | ||
import com.cp.compiler.models.ExecutionResponse; | ||
import com.cp.compiler.services.platform.containers.ContainerService; | ||
import com.cp.compiler.services.platform.resources.Resources; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public abstract class ExecutionStrategyDecorator extends ExecutionStrategy { | ||
|
||
/** | ||
* Instantiates a new Execution strategy. | ||
* | ||
* @param containerService the container service | ||
* @param meterRegistry the meter registry | ||
* @param resources the resources | ||
*/ | ||
protected ExecutionStrategyDecorator(ContainerService containerService, MeterRegistry meterRegistry, Resources resources) { | ||
super(containerService, meterRegistry, resources); | ||
} | ||
|
||
@Override | ||
public ExecutionResponse run(Execution execution, boolean deleteImageAfterExecution) { | ||
|
||
long startTime = System.nanoTime(); | ||
|
||
var executionResponse = super.run(execution, deleteImageAfterExecution); | ||
|
||
long endTime = System.nanoTime(); | ||
long elapsedTime = endTime - startTime; | ||
|
||
// Convert elapsed time to seconds | ||
double elapsedTimeInMilliSeconds = (double) elapsedTime / 1_000_000; | ||
log.info("Total execution duration took {} milliseconds", elapsedTimeInMilliSeconds); | ||
|
||
// Update last execution time, used to suggest retry in case of a throttling. | ||
resources.lastExecutionDuration.set(elapsedTimeInMilliSeconds); | ||
|
||
return executionResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
src/main/java/com/cp/compiler/services/platform/resources/Resources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters