Merged in development (pull request #13)

Try to be more resilient to influx write errors.
This commit is contained in:
Mark Nellemann 2021-01-21 13:07:27 +00:00
commit aa611d989d
2 changed files with 14 additions and 10 deletions

View File

@ -1,3 +1,3 @@
id = hmci id = hmci
group = biz.nellemann.hmci group = biz.nellemann.hmci
version = 1.1.0 version = 1.1.1

View File

@ -16,7 +16,6 @@
package biz.nellemann.hmci; package biz.nellemann.hmci;
import biz.nellemann.hmci.Configuration.InfluxObject; import biz.nellemann.hmci.Configuration.InfluxObject;
import org.influxdb.BatchOptions;
import org.influxdb.InfluxDB; import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory; import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.BatchPoints; import org.influxdb.dto.BatchPoints;
@ -36,8 +35,8 @@ class InfluxClient {
private final static Logger log = LoggerFactory.getLogger(InfluxClient.class); private final static Logger log = LoggerFactory.getLogger(InfluxClient.class);
private static final int BATCH_ACTIONS_LIMIT = 5000; //private static final int BATCH_ACTIONS_LIMIT = 5000;
private static final int BATCH_INTERVAL_DURATION = 1000; //private static final int BATCH_INTERVAL_DURATION = 1000;
final private String url; final private String url;
@ -47,6 +46,7 @@ class InfluxClient {
private InfluxDB influxDB; private InfluxDB influxDB;
private BatchPoints batchPoints; private BatchPoints batchPoints;
private int errorCounter = 0;
InfluxClient(InfluxObject config) { InfluxClient(InfluxObject config) {
@ -64,7 +64,7 @@ class InfluxClient {
} }
boolean connected = false; boolean connected = false;
int errors = 0; int loginErrors = 0;
do { do {
try { try {
@ -75,7 +75,7 @@ class InfluxClient {
connected = true; connected = true;
} catch(Exception e) { } catch(Exception e) {
sleep(15 * 1000); sleep(15 * 1000);
if(errors++ > 3) { if(loginErrors++ > 3) {
log.error("login() error, giving up - " + e.getMessage()); log.error("login() error, giving up - " + e.getMessage());
throw new RuntimeException(e); throw new RuntimeException(e);
} else { } else {
@ -105,11 +105,15 @@ class InfluxClient {
synchronized void writeBatchPoints() throws Exception { synchronized void writeBatchPoints() throws Exception {
log.debug("writeBatchPoints()"); log.debug("writeBatchPoints()");
try { try {
influxDB.writeWithRetry(batchPoints); influxDB.write(batchPoints);
} catch(Exception e) { } catch(Exception e) {
log.error("writeBatchPoints() error - " + e.getMessage()); log.error("writeBatchPoints() error - " + e.getMessage(), e);
logoff(); if(++errorCounter > 3) {
login(); log.info("writeBatchPoints() trying to logout / login");
errorCounter = 0;
logoff();
login();
}
} }
} }