Skip to content

Commit 6fc31ac

Browse files
authored
feat(service): add support for anchor paths (#127)
1 parent 5d3cbc4 commit 6fc31ac

File tree

9 files changed

+47
-15
lines changed

9 files changed

+47
-15
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# direnv
2-
.direnv
32
.envrc
3+
.direnv
44

55
# Testing
6-
config.toml
6+
/config.*
77
autopulse.log
88
data
99
/target

src/service/runner.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ use crate::{
1313
};
1414
use diesel::{BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl};
1515
use std::{path::PathBuf, sync::Arc};
16+
use tokio::sync::Mutex;
1617
use tracing::{error, info, warn};
1718

1819
pub(super) struct PulseRunner {
1920
webhooks: Arc<WebhookManager>,
2021
settings: Arc<Settings>,
2122
pool: Arc<DbPool>,
23+
24+
anchors_available: Arc<Mutex<bool>>,
2225
}
2326

2427
impl PulseRunner {
25-
pub const fn new(
26-
settings: Arc<Settings>,
27-
pool: Arc<DbPool>,
28-
webhooks: Arc<WebhookManager>,
29-
) -> Self {
28+
pub fn new(settings: Arc<Settings>, pool: Arc<DbPool>, webhooks: Arc<WebhookManager>) -> Self {
3029
Self {
3130
webhooks,
3231
settings,
3332
pool,
33+
anchors_available: Arc::new(Mutex::new(true)),
3434
}
3535
}
3636

@@ -268,6 +268,24 @@ impl PulseRunner {
268268
}
269269

270270
pub async fn run(&self) -> anyhow::Result<()> {
271+
let set_anchors_available = self.settings.anchors.iter().all(|anchor| anchor.exists());
272+
273+
let mut anchors_available = self.anchors_available.lock().await;
274+
if set_anchors_available != *anchors_available {
275+
if set_anchors_available {
276+
info!("anchors are available again, continuing");
277+
} else {
278+
warn!("anchors are not available, pausing");
279+
}
280+
*anchors_available = set_anchors_available;
281+
}
282+
283+
if !*anchors_available {
284+
return Ok(());
285+
}
286+
287+
drop(anchors_available);
288+
271289
self.update_found_status().await?;
272290
self.update_process_status().await?;
273291
self.cleanup().await?;

src/service/targets/autopulse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Autopulse {
5656
}
5757

5858
impl TargetProcess for Autopulse {
59-
async fn process<'a>(&self, evs: &[&'a ScanEvent]) -> anyhow::Result<Vec<String>> {
59+
async fn process(&self, evs: &[&ScanEvent]) -> anyhow::Result<Vec<String>> {
6060
let mut succeded = Vec::new();
6161

6262
for ev in evs {

src/service/targets/emby.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl Emby {
285285
}
286286

287287
impl TargetProcess for Emby {
288-
async fn process<'a>(&self, evs: &[&'a ScanEvent]) -> anyhow::Result<Vec<String>> {
288+
async fn process(&self, evs: &[&ScanEvent]) -> anyhow::Result<Vec<String>> {
289289
let libraries = self.libraries().await?;
290290

291291
let mut succeded = Vec::new();

src/service/targets/fileflows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl FileFlows {
3939
}
4040

4141
impl TargetProcess for FileFlows {
42-
async fn process<'a>(&self, evs: &[&'a ScanEvent]) -> anyhow::Result<Vec<String>> {
42+
async fn process(&self, evs: &[&ScanEvent]) -> anyhow::Result<Vec<String>> {
4343
let mut succeeded = Vec::new();
4444

4545
for ev in evs {

src/service/targets/plex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Plex {
228228
}
229229

230230
impl TargetProcess for Plex {
231-
async fn process<'a>(&self, evs: &[&'a ScanEvent]) -> anyhow::Result<Vec<String>> {
231+
async fn process(&self, evs: &[&ScanEvent]) -> anyhow::Result<Vec<String>> {
232232
let libraries = self.libraries().await?;
233233

234234
let mut succeeded = Vec::new();

src/service/targets/tdarr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Tdarr {
8080
}
8181

8282
impl TargetProcess for Tdarr {
83-
async fn process<'a>(&self, evs: &[&'a ScanEvent]) -> anyhow::Result<Vec<String>> {
83+
async fn process(&self, evs: &[&ScanEvent]) -> anyhow::Result<Vec<String>> {
8484
let mut succeeded = Vec::new();
8585

8686
self.scan(evs).await?;

src/settings/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use auth::Auth;
44
use config::Config;
55
use opts::Opts;
66
use serde::Deserialize;
7-
use std::collections::HashMap;
7+
use std::{collections::HashMap, path::PathBuf};
88
use target::Target;
99
use timer::Timer;
1010
use trigger::Trigger;
@@ -123,6 +123,20 @@ pub struct Settings {
123123

124124
#[serde(default)]
125125
pub webhooks: HashMap<String, Webhook>,
126+
127+
/// List of paths to anchor the service to
128+
///
129+
/// This is useful to prevent the service notifying a target when the drive is not mounted or visible
130+
/// The contents of the file/directory are not tampered with, only the presence of the file/directory is checked
131+
///
132+
/// Example:
133+
/// ```yml
134+
/// anchors:
135+
/// - /mnt/media/tv # Directory
136+
/// - /mnt/media/anchor # File
137+
/// ```
138+
#[serde(default)]
139+
pub anchors: Vec<PathBuf>,
126140
}
127141

128142
impl Settings {

src/settings/target.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::{
99
};
1010

1111
pub trait TargetProcess {
12-
fn process<'a>(
12+
fn process(
1313
&self,
14-
evs: &[&'a ScanEvent],
14+
evs: &[&ScanEvent],
1515
) -> impl std::future::Future<Output = anyhow::Result<Vec<String>>> + Send;
1616
}
1717

0 commit comments

Comments
 (0)