mirror of
https://github.com/jlengrand/cellar.git
synced 2026-03-10 08:01:19 +00:00
Adding some dumb resiliency
This commit is contained in:
@@ -43,7 +43,7 @@ public final class Main {
|
||||
Server server = startServer();
|
||||
startMonitoring();
|
||||
|
||||
System.out.println("http://localhost:" + server.port() + "/greet");
|
||||
System.out.println("http://localhost:" + server.port());
|
||||
}
|
||||
|
||||
static void startMonitoring(){
|
||||
|
||||
@@ -20,19 +20,26 @@ public class SensorApi {
|
||||
connection.init();
|
||||
}
|
||||
|
||||
public void add(SensorValue values) throws ExecutionException, InterruptedException {
|
||||
Value addDataResult = connection.getClient().query(
|
||||
Create(
|
||||
Collection(Language.Value(COLLECTION_NAME)),
|
||||
Obj("data",
|
||||
Obj( "temperature", Language.Value(values.getTemperature()),
|
||||
"humidity", Language.Value(values.getHumidity()) ,
|
||||
"reading", Language.Value(values.getReading()),
|
||||
"timestamp", Language.Value(Instant.now())
|
||||
)
|
||||
)
|
||||
)
|
||||
).get();
|
||||
System.out.println("Added sensor data to collection " + COLLECTION_NAME + ":\n " + addDataResult + "\n");
|
||||
public void add(SensorValue values) {
|
||||
Value addDataResult = null;
|
||||
try {
|
||||
addDataResult = connection.getClient().query(
|
||||
Create(
|
||||
Collection(Language.Value(COLLECTION_NAME)),
|
||||
Obj("data",
|
||||
Obj( "temperature", Language.Value(values.getTemperature()),
|
||||
"humidity", Language.Value(values.getHumidity()) ,
|
||||
"reading", Language.Value(values.getReading()),
|
||||
"timestamp", Language.Value(Instant.now())
|
||||
)
|
||||
)
|
||||
)
|
||||
).get();
|
||||
System.out.println("Added sensor data to collection " + COLLECTION_NAME + ":\n " + addDataResult + "\n");
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
System.out.println("Failing to upload data! Restarting Connection");
|
||||
e.printStackTrace();
|
||||
connection.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user