always show ticker update on screen
rolling log to file.
This commit is contained in:
elroy 2017-07-05 23:05:56 +02:00
parent 8ddab27903
commit 87080bdc05
7 changed files with 50 additions and 33 deletions

View File

@ -32,8 +32,7 @@
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-freemarker:1.5.4.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-freemarker:1.5.4.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.26-incubating" level="project" /> <orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.26-incubating" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.6.4" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.8.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.8.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.8.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.8.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.8.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-jcl:2.8.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-jcl:2.8.2" level="project" />

View File

@ -46,16 +46,10 @@
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.7.25</version> <version>1.7.25</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>log4j-slf4j-impl</artifactId>
<version>2.8.2</version> <version>2.8.2</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>

View File

@ -14,13 +14,12 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
import java.util.concurrent.Executor; import java.util.concurrent.Executors;
/** /**
* Created by Elroy on 29-6-2017. * Created by Elroy on 29-6-2017.
@ -55,14 +54,9 @@ public class Application {
return factory; return factory;
} }
@Bean
public Executor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}
@Bean @Bean
public TaskScheduler taskScheduler() { public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler(); return new ConcurrentTaskScheduler(Executors.newScheduledThreadPool(5));
} }
@Bean @Bean

View File

@ -8,6 +8,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import net.jodah.failsafe.Failsafe; import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.RetryPolicy; import net.jodah.failsafe.RetryPolicy;
import nl.komtek.gpi.utils.ProxyHandledException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -155,7 +157,6 @@ public class GunbotProxyService {
@Cacheable(value = "chartData", key = "#currencyPair") @Cacheable(value = "chartData", key = "#currencyPair")
public String getChartData(String currencyPair, String start, long period) { public String getChartData(String currencyPair, String start, long period) {
logger.debug("chartData: " + currencyPair + " -- start:" + start + " -- period:" + period);
long startLong = 0; long startLong = 0;
if (start.indexOf(".") > 0) { if (start.indexOf(".") > 0) {
startLong = Long.valueOf(start.substring(0, start.indexOf("."))); startLong = Long.valueOf(start.substring(0, start.indexOf(".")));
@ -166,7 +167,9 @@ public class GunbotProxyService {
while (true) { while (true) {
try { try {
String result = publicClient.getChartData(currencyPair, period, startLong); String result = publicClient.getChartData(currencyPair, period, startLong);
return analyzeResult(result); result = analyzeResult(result);
logger.debug("chartData: " + currencyPair + " -- start:" + start + " -- period:" + period + " -- " + result);
return result;
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
} }
@ -183,7 +186,12 @@ public class GunbotProxyService {
String result = Failsafe.with(retryPolicy) String result = Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException) .onFailedAttempt(this::handleException)
.get(() -> analyzeResult(publicClient.returnTicker())); .get(() -> analyzeResult(publicClient.returnTicker()));
logger.debug("ticker: " + result);
if (logger.getLevel().isLessSpecificThan(Level.DEBUG)) {
logger.info("ticker updated");
} else {
logger.info("ticker: " + result);
}
return result; return result;
} }
@ -346,20 +354,20 @@ public class GunbotProxyService {
private String analyzeResult(String result) { private String analyzeResult(String result) {
if (result != null && result.contains("Nonce")) { if (result != null && result.contains("Nonce")) {
throw new RuntimeException("nonce error: " + result); throw new ProxyHandledException("nonce error: " + result);
} else if (result == null) { } else if (result == null) {
throw new RuntimeException("No value was returned"); throw new ProxyHandledException("No value was returned");
} }
return result; return result;
} }
private void handleException(Throwable e) { private void handleException(Throwable e) {
if (!(e instanceof RuntimeException)) { if (e instanceof ProxyHandledException) {
logger.error(e.toString()); logger.debug(e.toString());
} else if (e instanceof NullPointerException) { } else if (e instanceof NullPointerException) {
logger.error("Something is really wrong", e); logger.error("Something is really wrong", e);
} else { } else {
logger.debug(e.toString()); logger.error(e.toString());
} }
} }

View File

@ -0,0 +1,11 @@
package nl.komtek.gpi.utils;
/**
* Created by Elroy on 05-7-2017.
*/
public class ProxyHandledException extends RuntimeException {
public ProxyHandledException(String message) {
super(message);
}
}

View File

@ -18,7 +18,7 @@ public class ScheduledTasks {
@Autowired @Autowired
private GunbotProxyService gunbotProxyService; private GunbotProxyService gunbotProxyService;
@Scheduled(fixedDelay = Long.MAX_VALUE) @Scheduled(fixedRate = Long.MAX_VALUE)
public void itWorks() { public void itWorks() {
if (gunbotProxyService.isUsingMultipleMarkets()) { if (gunbotProxyService.isUsingMultipleMarkets()) {
logger.info("Running in multimarket MODE!"); logger.info("Running in multimarket MODE!");

View File

@ -1,25 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="900"> <Configuration status="WARN" monitorInterval="900">
<Properties>
<Property name="baseDir">logs</Property>
</Properties>
<Appenders> <Appenders>
<Console name="Console" target="SYSTEM_OUT"> <Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %p %c{1} - %m%n"/> <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %p %c{1} - %m%n"/>
</Console> </Console>
<File name="File" fileName="GunbotProxy.log"> <RollingFile name="RollingFile" fileName="${baseDir}/GunbotProxy.log"
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %p %c{1} - %m%n"/> filePattern="${baseDir}/$${date:yyyy-MM}/GunbotProxy-%d{yyyy-MM-dd}.log.gz">
</File> <PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
<DefaultRolloverStrategy>
<Delete basePath="${baseDir}" maxDepth="2">
<IfFileName glob="*/GunbotProxy.log-*.log.gz"/>
<IfLastModified age="1d"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</Appenders> </Appenders>
<Loggers> <Loggers>
<Logger name="nl.komtek" level="info" additivity="false"> <Logger name="nl.komtek" level="debug" additivity="false">
<AppenderRef ref="Console"/> <AppenderRef ref="Console" level="info"/>
<AppenderRef ref="File"/> <AppenderRef ref="RollingFile" level="debug"/>
</Logger> </Logger>
<Logger name="org.apache" level="error" additivity="false"> <Logger name="org.apache" level="error" additivity="false">
<AppenderRef ref="Console"/> <AppenderRef ref="Console"/>
<AppenderRef ref="File"/> <AppenderRef ref="RollingFile"/>
</Logger> </Logger>
<Root level="error"> <Root level="error">
<AppenderRef ref="Console"/> <AppenderRef ref="Console"/>
<AppenderRef ref="File"/> <AppenderRef ref="RollingFile"/>
</Root> </Root>
</Loggers> </Loggers>
</Configuration> </Configuration>