Skip to content

Commit

Permalink
Merge pull request #7404 from Turbo87/simplify-environment
Browse files Browse the repository at this point in the history
background_jobs: Simplify `Environment` struct
  • Loading branch information
Turbo87 authored Oct 31, 2023
2 parents 2a45482 + 81cb54b commit c1ae193
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
20 changes: 2 additions & 18 deletions src/background_jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub struct RenderAndUploadReadmeJob {
}

pub struct Environment {
index: Arc<Mutex<Repository>>,
index: Mutex<Repository>,
http_client: AssertUnwindSafe<Client>,
cloudfront: Option<CloudFront>,
fastly: Option<Fastly>,
Expand All @@ -331,25 +331,9 @@ impl Environment {
cloudfront: Option<CloudFront>,
fastly: Option<Fastly>,
storage: Arc<Storage>,
) -> Self {
Self::new_shared(
Arc::new(Mutex::new(index)),
http_client,
cloudfront,
fastly,
storage,
)
}

pub fn new_shared(
index: Arc<Mutex<Repository>>,
http_client: Client,
cloudfront: Option<CloudFront>,
fastly: Option<Fastly>,
storage: Arc<Storage>,
) -> Self {
Self {
index,
index: Mutex::new(index),
http_client: AssertUnwindSafe(http_client),
cloudfront,
fastly,
Expand Down
8 changes: 3 additions & 5 deletions src/bin/background-worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use diesel::r2d2;
use diesel::r2d2::ConnectionManager;
use reqwest::blocking::Client;
use secrecy::ExposeSecret;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::thread::sleep;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -66,9 +66,7 @@ fn main() {

let clone_start = Instant::now();
let repository_config = RepositoryConfig::from_environment();
let repository = Arc::new(Mutex::new(
Repository::open(&repository_config).expect("Failed to clone index"),
));
let repository = Repository::open(&repository_config).expect("Failed to clone index");

let clone_duration = clone_start.elapsed();
info!(duration = ?clone_duration, "Index cloned");
Expand All @@ -82,7 +80,7 @@ fn main() {
.build()
.expect("Couldn't build client");

let environment = Environment::new_shared(repository, client, cloudfront, fastly, storage);
let environment = Environment::new(repository, client, cloudfront, fastly, storage);

let environment = Arc::new(Some(environment));

Expand Down

0 comments on commit c1ae193

Please sign in to comment.