configurable filtering expression evaluation timeout

This commit is contained in:
Athou
2024-08-17 23:26:42 +02:00
parent 3627ee369d
commit ede7834cb8
3 changed files with 18 additions and 2 deletions

View File

@@ -167,6 +167,12 @@ public interface CommaFeedConfiguration {
*/
@WithDefault("0")
Duration userInactivityPeriod();
/**
* Duration after which the evaluation of a filtering expresion to mark an entry as read is considered to have timed out.
*/
@WithDefault("500ms")
Duration filteringExpressionEvaluationTimeout();
}
interface Database {

View File

@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.LogFactory;
import org.jsoup.Jsoup;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.backend.model.FeedEntry;
import jakarta.inject.Singleton;
@@ -35,6 +36,7 @@ public class FeedEntryFilteringService {
private static final JexlEngine ENGINE = initEngine();
private final ExecutorService executor = Executors.newCachedThreadPool();
private final CommaFeedConfiguration config;
private static JexlEngine initEngine() {
// classloader that prevents object creation
@@ -96,8 +98,9 @@ public class FeedEntryFilteringService {
Future<Object> future = executor.submit(callable);
Object result;
try {
result = future.get(500, TimeUnit.MILLISECONDS);
result = future.get(config.feedRefresh().filteringExpressionEvaluationTimeout().toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new FeedEntryFilterException("interrupted while evaluating expression " + filter, e);
} catch (ExecutionException e) {
throw new FeedEntryFilterException("Exception while evaluating expression " + filter, e);