Skip to content

Commit

Permalink
feat: add retry functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Jul 1, 2023
1 parent b45c55d commit ccf368d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
axum = "0.6.18"
retry = "2.0.0"
serde = { version = "^1.0.164", features = ["derive"] }
tectonic = "0.14.1"
tokio = { version = "1.29.1", features = ["full"] }
Expand Down
18 changes: 9 additions & 9 deletions src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use axum::{
body::Body,
http::header::{CONTENT_DISPOSITION, CONTENT_TYPE},
http::StatusCode,
response::{IntoResponse, Response},
Json,
};

use axum::body::Body;
use axum::http::header::{CONTENT_DISPOSITION, CONTENT_TYPE};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::Json;
use retry::delay::NoDelay;
use retry::retry;
use serde::Deserialize;
use tectonic::latex_to_pdf;

Expand All @@ -15,7 +14,8 @@ pub struct CompileSchema {
}

pub async fn compile(Json(payload): Json<CompileSchema>) -> impl IntoResponse {
let pdf = latex_to_pdf(payload.latex).expect("Unable to convert LaTeX to PDF");
let pdf = retry(NoDelay.take(1), || latex_to_pdf(&payload.latex))
.expect("Unable to convert LaTeX to PDF");
let body = Body::from(pdf);

Response::builder()
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
mod compile;
mod index;

use axum::{
routing::{get, post},
Router, Server,
};

use axum::routing::{get, post};
use axum::{Router, Server};
use compile::compile;
use index::index;
use std::env::var;
Expand Down

0 comments on commit ccf368d

Please sign in to comment.