Use a limited threadpool for handling pubsub requests.

This commit is contained in:
Kavin 2023-07-06 14:56:28 +01:00
parent 1dbda14335
commit f9289a05d1
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F
1 changed files with 7 additions and 4 deletions

View File

@ -76,18 +76,21 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
.map(GET, "/webhooks/pubsub", AsyncServlet.ofBlocking(executor, request -> {
var topic = request.getQueryParameter("hub.topic");
if (topic != null)
Multithreading.runAsync(() -> {
Multithreading.runAsyncLimited(() -> {
String channelId = StringUtils.substringAfter(topic, "channel_id=");
PubSubHelper.updatePubSub(channelId);
});
return HttpResponse.ok200().withPlainText(Objects.requireNonNull(request.getQueryParameter("hub.challenge")));
var challenge = request.getQueryParameter("hub.challenge");
return HttpResponse.ok200()
.withPlainText(Objects.requireNonNullElse(challenge, "ok"));
})).map(POST, "/webhooks/pubsub", AsyncServlet.ofBlocking(executor, request -> {
try {
SyndFeed feed = new SyndFeedInput().build(
new InputSource(new ByteArrayInputStream(request.loadBody().getResult().asArray())));
Multithreading.runAsync(() -> {
Multithreading.runAsyncLimited(() -> {
for (var entry : feed.getEntries()) {
String url = entry.getLinks().get(0).getHref();
String videoId = StringUtils.substring(url, -11);
@ -95,7 +98,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
if (DatabaseHelper.doesVideoExist(s, videoId))
continue;
}
Multithreading.runAsync(() -> {
Multithreading.runAsyncLimited(() -> {
try {
Sentry.setExtra("videoId", videoId);
var extractor = YOUTUBE_SERVICE.getStreamExtractor("https://youtube.com/watch?v=" + videoId);