Commit f1c0112e authored by youxiaoji's avatar youxiaoji

* [playwright 初始化后不再初始化]

parent 488dd115
...@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import jakarta.annotation.PreDestroy; import jakarta.annotation.PreDestroy;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
...@@ -54,8 +55,10 @@ public class PlaywrightManagerImpl implements PlaywrightManager { ...@@ -54,8 +55,10 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
log.info("正在初始化Playwright管理器..."); log.info("正在初始化Playwright管理器...");
// 创建Playwright实例 // 创建Playwright实例
if (playwright == null) {
this.playwright = Playwright.create(); this.playwright = Playwright.create();
}
if (browser == null) {
// 启动Chrome浏览器,无头模式 // 启动Chrome浏览器,无头模式
this.browser = playwright.chromium().launch(new BrowserType.LaunchOptions() this.browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
.setHeadless(true) .setHeadless(true)
...@@ -77,7 +80,7 @@ public class PlaywrightManagerImpl implements PlaywrightManager { ...@@ -77,7 +80,7 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
"--disable-gpu", "--disable-gpu",
"--remote-allow-origins=*"))); "--remote-allow-origins=*")));
}); });
}
// 每5分钟检查一次超时的用户上下文 // 每5分钟检查一次超时的用户上下文
cleanupScheduler.scheduleAtFixedRate(this::cleanupExpiredContexts, cleanupScheduler.scheduleAtFixedRate(this::cleanupExpiredContexts,
5, 3600, TimeUnit.MINUTES); 5, 3600, TimeUnit.MINUTES);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment