Skip to content

Commit

Permalink
command execution timeout value bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
detsam committed May 27, 2015
1 parent 8c00775 commit b1dd466
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@
* of this implementation.
* </p>
*
* <p>
* Command execution timeout can be modified using application
* property <i>redgreen.hystrix.simpleFailoverLine.commandTimeout</i> ( note, a value should be defined in millis ).
* </p>
*
* @since 0.1.0
*/
public class HystrixSimpleFailoverLine implements FailoverLine {

/**
* Defines {@code Hystrix} command key, this constant can be used as the reference
* to this line execution command.
*
* @since 0.1.0
*/
public static final String HYSTRIX_COMMAND_KEY = "SimpleFailoverLineExecution";

// NOTE: ResourceHttpMessageConverter used to handle all possible content-types
private RestTemplate restTemplate = new RestTemplate(
Arrays.asList(new ResourceHttpMessageConverter())
Expand All @@ -65,12 +68,9 @@ public HystrixSimpleFailoverLine(RedgreenBundleRepostitory redgreenBundleReposti
this.bundleRepostitory = redgreenBundleRepostitory;
}

@HystrixCommand(fallbackMethod = "performFallback",
@HystrixCommand(commandKey=HYSTRIX_COMMAND_KEY, fallbackMethod = "performFallback",
commandProperties = {
@HystrixProperty(name="circuitBreaker.enabled",
value="false"),
@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",
value="${redgreen.hystrix.simpleFailoverLine.commandTimeout}")
@HystrixProperty(name="circuitBreaker.enabled", value="false"),
}
)
@Override
Expand All @@ -96,7 +96,7 @@ public Object performFallback(Supplier<RedgreenRequest> requestSupplier) {
return redgreenBundle.mapRedResources((r) -> doSafeResourceRequest(r, requestSupplier.get()))
.filter((r) -> r != null)
.findFirst()
// TODO: define specific exception
// TODO: define specific exception
.orElseThrow(RuntimeException::new);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.ametiste.redgreen.configuration;

import com.netflix.config.ConfigurationManager;
import org.ametiste.redgreen.application.FailoverLine;
import org.ametiste.redgreen.application.HystrixSimpleFailoverLine;
import org.ametiste.redgreen.data.RedgreenBundleRepostitory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -15,12 +17,17 @@
* </p>
*
* <p>
* Note, in the version 0.1.0 it's only one possible {@link FailoverLine}
* configuration.
* Command execution timeout can be modified using application
* property <i>redgreen.hystrix.simpleFailoverLine.commandTimeout</i> ( note, a value should be defined in millis ).
* </p>
*
* <p>
* See {@link HystrixSimpleFailoverLine} documentaion for configuration properties details.
* See {@link HystrixSimpleFailoverLine} documentaion for implementation details.
* </p>
*
* <p>
* Note, in the version 0.1.0 it's only one possible {@link FailoverLine}
* configuration.
* </p>
*
* @see HystrixSimpleFailoverLine
Expand All @@ -29,11 +36,27 @@
@Configuration
public class HystrixSimpleFailoverLineConfiguration {

private static final String COMMAND_EXEC_TIMEOUT_PROPERTY =
"hystrix.command." +
HystrixSimpleFailoverLine.HYSTRIX_COMMAND_KEY +
".execution.isolation.thread.timeoutInMilliseconds";

@Autowired
private RedgreenBundleRepostitory bundleRepostitory;

// TODO: extract to boot properties class
@Value("${redgreen.hystrix.simpleFailoverLine.commandTimeout:300}")
private String commandExecutionTimeout;

@Bean
public HystrixSimpleFailoverLine simpleFailoverLine() {

// NOTE: there are no another way to set values obtained from properties,
// hystrix-javanica does not support spring's properties placeholders atm
ConfigurationManager
.getConfigInstance()
.setProperty(COMMAND_EXEC_TIMEOUT_PROPERTY, commandExecutionTimeout);

return new HystrixSimpleFailoverLine(bundleRepostitory);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
logging.level.ROOT=INFO

redgreen.hystrix.simpleFailoverLine.commandTimeout=900000
redgreen.hystrix.simpleFailoverLine.commandTimeout=100

redgreen.direct.bundles.test-bundle.green=http://example.xcom/
redgreen.direct.bundles.test-bundle.red=http://example.com/

0 comments on commit b1dd466

Please sign in to comment.