Skip to content

Commit

Permalink
Make timeout configurable
Browse files Browse the repository at this point in the history
Resolves #34

Signed-off-by: Hollow Man <hollowman@opensuse.org>
  • Loading branch information
HollowMan6 committed Dec 13, 2023
1 parent 1015b6f commit c5c48f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let launch_opts = LaunchOptionsBuilder::default()
.headless(true)
.sandbox(false)
.idle_browser_timeout(Duration::from_secs(600))
.idle_browser_timeout(Duration::from_secs(cfg.timeout))
.path(browser_binary)
.args(vec![
OsStr::new("--disable-pdf-tagging"),
Expand Down Expand Up @@ -211,7 +211,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new browser window.
let browser = Browser::new(launch_opts)?;
let tab = browser.new_tab()?;
tab.set_default_timeout(std::time::Duration::from_secs(300));
tab.set_default_timeout(std::time::Duration::from_secs(cfg.timeout));
let page = tab.navigate_to(&url)?.wait_until_navigated()?;
page.wait_for_element("#content-has-all-loaded-for-mdbook-pdf-generation")?;

Expand Down Expand Up @@ -284,6 +284,7 @@ extern crate serde_derive;
#[serde(default, rename_all = "kebab-case")]
pub struct PrintOptions {
pub trying_times: u64,
pub timeout: u64,
pub browser_binary_path: String,
pub static_site_url: String,
pub landscape: bool,
Expand Down Expand Up @@ -313,6 +314,7 @@ impl Default for PrintOptions {
fn default() -> Self {
PrintOptions {
trying_times: 1u64,
timeout: 600u64,
browser_binary_path: "".to_string(),
static_site_url: "".to_string(),
landscape: false,
Expand Down
2 changes: 2 additions & 0 deletions test_doc/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ title = "An Example"
[output.pdf]
## Set for auto-retrying if failed to generate PDF.
# trying-times = 1
## Set the timeout in seconds.
# timeout = 600
## This backend only support latest Chromium based browsers, not Safari and Firefox currently.
## If needed, please specify the full path.
## If you specify the wrong binary, chances are that there will be a timeout error.
Expand Down

0 comments on commit c5c48f2

Please sign in to comment.