rename git watcher -> session watcher

This commit is contained in:
Nikita Galaiko 2023-03-03 10:45:54 +01:00
parent d85b40f472
commit d962e2d7d1
2 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,5 @@
mod delta;
mod git;
mod session;
pub use self::delta::WatcherCollection;
use crate::{events, projects, users};
@ -7,7 +7,7 @@ use anyhow::Result;
use std::sync::mpsc;
pub struct Watcher<'a> {
git_watcher: git::GitWatcher,
session_watcher: session::SessionWatcher,
delta_watcher: delta::DeltaWatchers<'a>,
}
@ -17,10 +17,10 @@ impl<'a> Watcher<'a> {
projects_storage: projects::Storage,
users_storage: users::Storage,
) -> Self {
let git_watcher = git::GitWatcher::new(projects_storage, users_storage);
let session_watcher = session::SessionWatcher::new(projects_storage, users_storage);
let delta_watcher = delta::DeltaWatchers::new(watchers);
Self {
git_watcher,
session_watcher,
delta_watcher,
}
}
@ -31,13 +31,14 @@ impl<'a> Watcher<'a> {
project: &projects::Project,
) -> Result<()> {
self.delta_watcher.watch(sender.clone(), project.clone())?;
self.git_watcher.watch(sender.clone(), project.clone())?;
self.session_watcher
.watch(sender.clone(), project.clone())?;
Ok(())
}
pub fn unwatch(&self, project: projects::Project) -> Result<()> {
self.delta_watcher.unwatch(project)?;
// TODO: how to unwatch git ?
// TODO: how to unwatch session ?
Ok(())
}
}

View File

@ -11,12 +11,12 @@ const FIVE_MINUTES: u128 = Duration::new(5 * 60, 0).as_millis();
const ONE_HOUR: u128 = Duration::new(60 * 60, 0).as_millis();
#[derive(Debug, Clone)]
pub struct GitWatcher {
pub struct SessionWatcher {
projects_storage: projects::Storage,
users_storage: users::Storage,
}
impl GitWatcher {
impl SessionWatcher {
pub fn new(projects_storage: projects::Storage, users_storage: users::Storage) -> Self {
Self {
projects_storage,
@ -42,6 +42,7 @@ impl GitWatcher {
})?;
match self.check_for_changes(&project, &user)? {
Some(session) => {
// index
sender
.send(events::Event::session(&project, &session))
.with_context(|| {
@ -67,9 +68,9 @@ impl GitWatcher {
sender: mpsc::Sender<events::Event>,
project: projects::Project,
) -> Result<()> {
log::info!("Watching git for {}", project.path);
log::info!("Watching sessions for {}", project.path);
let shared_self = std::sync::Arc::new(self.clone());
let shared_self = self.clone();
let self_copy = shared_self.clone();
let project_id = project.id;