websocket can now be disabled, the websocket ping interval and the tree reload interval can now be configured (#1132)

This commit is contained in:
Athou
2023-12-21 20:27:30 +01:00
parent bdabd9db0d
commit 5541cc9fbe
10 changed files with 104 additions and 25 deletions

View File

@@ -13,6 +13,7 @@ import be.tomcools.dropwizard.websocket.WebsocketBundleConfiguration;
import be.tomcools.dropwizard.websocket.WebsocketConfiguration;
import io.dropwizard.core.Configuration;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.util.Duration;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
@@ -62,8 +63,7 @@ public class CommaFeedConfiguration extends Configuration implements WebsocketBu
@Override
public WebsocketConfiguration getWebsocketConfiguration() {
WebsocketConfiguration config = new WebsocketConfiguration();
// the client sends ping messages every minute, so we can close idle connections a little bit after that
config.setMaxSessionIdleTimeout(90000L);
config.setMaxSessionIdleTimeout(getApplicationSettings().getWebsocketPingInterval().toMilliseconds() + 10000);
return config;
}
@@ -164,6 +164,12 @@ public class CommaFeedConfiguration extends Configuration implements WebsocketBu
private String userAgent;
private Boolean websocketEnabled = true;
private Duration websocketPingInterval = Duration.minutes(15);
private Duration treeReloadInterval = Duration.seconds(30);
public Date getUnreadThreshold() {
int keepStatusDays = getKeepStatusDays();
return keepStatusDays > 0 ? DateUtils.addDays(new Date(), -1 * keepStatusDays) : null;

View File

@@ -32,4 +32,13 @@ public class ServerInfo implements Serializable {
@Schema(requiredMode = RequiredMode.REQUIRED)
private boolean demoAccountEnabled;
@Schema(requiredMode = RequiredMode.REQUIRED)
private boolean websocketEnabled;
@Schema(requiredMode = RequiredMode.REQUIRED)
private long websocketPingInterval;
@Schema(requiredMode = RequiredMode.REQUIRED)
private long treeReloadInterval;
}

View File

@@ -56,6 +56,9 @@ public class ServerREST {
infos.setGoogleAnalyticsCode(config.getApplicationSettings().getGoogleAnalyticsTrackingCode());
infos.setSmtpEnabled(StringUtils.isNotBlank(config.getApplicationSettings().getSmtpHost()));
infos.setDemoAccountEnabled(config.getApplicationSettings().getCreateDemoAccount());
infos.setWebsocketEnabled(config.getApplicationSettings().getWebsocketEnabled());
infos.setWebsocketPingInterval(config.getApplicationSettings().getWebsocketPingInterval().toMilliseconds());
infos.setTreeReloadInterval(config.getApplicationSettings().getTreeReloadInterval().toMilliseconds());
return Response.ok(infos).build();
}

View File

@@ -0,0 +1,22 @@
package com.commafeed.integration.rest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.commafeed.frontend.model.ServerInfo;
import com.commafeed.integration.BaseIT;
public class ServerIT extends BaseIT {
@Test
void getServerInfos() {
ServerInfo serverInfos = getClient().target(getApiBaseUrl() + "server/get").request().get(ServerInfo.class);
Assertions.assertTrue(serverInfos.isAllowRegistrations());
Assertions.assertTrue(serverInfos.isSmtpEnabled());
Assertions.assertTrue(serverInfos.isDemoAccountEnabled());
Assertions.assertTrue(serverInfos.isWebsocketEnabled());
Assertions.assertEquals(900000, serverInfos.getWebsocketPingInterval());
Assertions.assertEquals(30000, serverInfos.getTreeReloadInterval());
}
}

View File

@@ -78,6 +78,15 @@ app:
# user-agent string that will be used by the http client, leave empty for the default one
userAgent:
# enable websocket connection so the server can notify the web client that there are new entries for your feeds
websocketEnabled: true
# interval at which the client will send a ping message on the websocket to keep the connection alive
websocketPingInterval: 15m
# if websocket is disabled or the connection is lost, the client will reload the feed tree at this interval
treeReloadInterval: 30s
# Database connection
# -------------------
# for MariaDB