Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions crates/pet/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use pet_conda::Conda;
use pet_conda::CondaLocator;
use pet_core::{
os_environment::{Environment, EnvironmentApi},
reporter::Reporter,
Configuration, Locator,
};
use pet_jsonrpc::{
Expand All @@ -32,7 +31,6 @@ use std::{
use crate::{find::find_and_report_envs, locators::create_locators};

pub struct Context {
reporter: Arc<dyn Reporter>,
configuration: RwLock<Configuration>,
locators: Arc<Vec<Arc<dyn Locator>>>,
conda_locator: Arc<Conda>,
Expand All @@ -48,12 +46,9 @@ pub fn start_jsonrpc_server() {
// These are globals for the the lifetime of the server.
// Hence passed around as Arcs via the context.
let environment = EnvironmentApi::new();
let jsonrpc_reporter = Arc::new(jsonrpc::create_reporter());
let reporter = Arc::new(CacheReporter::new(jsonrpc_reporter.clone()));
let conda_locator = Arc::new(Conda::from(&environment));
let poetry_locator = Arc::new(Poetry::from(&environment));
let context = Context {
reporter,
locators: create_locators(conda_locator.clone(), poetry_locator.clone(), &environment),
conda_locator,
poetry_locator,
Expand Down Expand Up @@ -123,9 +118,11 @@ pub fn handle_refresh(context: Arc<Context>, id: u32, _params: Value) {
// Start in a new thread, we can have multiple requests.
thread::spawn(move || {
let config = context.configuration.read().unwrap().clone();
let reporter = Arc::new(CacheReporter::new(Arc::new(jsonrpc::create_reporter())));

trace!("Start refreshing environments, config: {:?}", config);
let summary = find_and_report_envs(
context.reporter.as_ref(),
reporter.as_ref(),
config,
&context.locators,
context.os_environment.deref(),
Expand Down Expand Up @@ -167,9 +164,9 @@ pub fn handle_refresh(context: Arc<Context>, id: u32, _params: Value) {
.unwrap()
.conda_executable
.clone();
let reporter = context.reporter.clone();
let reporter_ref = reporter.clone();
thread::spawn(move || {
conda_locator.find_and_report_missing_envs(reporter.as_ref(), conda_executable);
conda_locator.find_and_report_missing_envs(reporter_ref.as_ref(), conda_executable);
Some(())
});

Expand All @@ -184,9 +181,10 @@ pub fn handle_refresh(context: Arc<Context>, id: u32, _params: Value) {
.unwrap()
.poetry_executable
.clone();
let reporter = context.reporter.clone();
let reporter_ref = reporter.clone();
thread::spawn(move || {
poetry_locator.find_and_report_missing_envs(reporter.as_ref(), poetry_executable);
poetry_locator
.find_and_report_missing_envs(reporter_ref.as_ref(), poetry_executable);
Some(())
});
}
Expand All @@ -212,8 +210,9 @@ pub fn handle_resolve(context: Arc<Context>, id: u32, params: Value) {
{
if let Some(resolved) = result.resolved {
// Gather telemetry of this resolved env and see what we got wrong.
let jsonrpc_reporter = jsonrpc::create_reporter();
let _ = report_inaccuracies_identified_after_resolving(
context.reporter.as_ref(),
&jsonrpc_reporter,
&result.discovered,
&resolved,
);
Expand Down