feat(network): Support for fetching all Sonarr tasks
This commit is contained in:
@@ -435,9 +435,9 @@ pub struct SystemStatus {
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Task {
|
||||
pub struct RadarrTask {
|
||||
pub name: String,
|
||||
pub task_name: TaskName,
|
||||
pub task_name: RadarrTaskName,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub interval: i64,
|
||||
pub last_execution: DateTime<Utc>,
|
||||
@@ -447,7 +447,7 @@ pub struct Task {
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Copy, ValueEnum)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub enum TaskName {
|
||||
pub enum RadarrTaskName {
|
||||
#[default]
|
||||
ApplicationCheckUpdate,
|
||||
Backup,
|
||||
@@ -462,7 +462,7 @@ pub enum TaskName {
|
||||
RssSync,
|
||||
}
|
||||
|
||||
impl Display for TaskName {
|
||||
impl Display for RadarrTaskName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let task_name = serde_json::to_string(&self)
|
||||
.expect("Unable to serialize task name")
|
||||
@@ -514,7 +514,7 @@ pub enum RadarrSerdeable {
|
||||
SecurityConfig(SecurityConfig),
|
||||
SystemStatus(SystemStatus),
|
||||
Tags(Vec<Tag>),
|
||||
Tasks(Vec<Task>),
|
||||
Tasks(Vec<RadarrTask>),
|
||||
Updates(Vec<Update>),
|
||||
AddMovieSearchResults(Vec<AddMovieSearchResult>),
|
||||
IndexerTestResults(Vec<IndexerTestResult>),
|
||||
@@ -555,7 +555,7 @@ serde_enum_from!(
|
||||
SecurityConfig(SecurityConfig),
|
||||
SystemStatus(SystemStatus),
|
||||
Tags(Vec<Tag>),
|
||||
Tasks(Vec<Task>),
|
||||
Tasks(Vec<RadarrTask>),
|
||||
Updates(Vec<Update>),
|
||||
AddMovieSearchResults(Vec<AddMovieSearchResult>),
|
||||
IndexerTestResults(Vec<IndexerTestResult>),
|
||||
|
||||
@@ -8,7 +8,7 @@ mod tests {
|
||||
AddMovieSearchResult, BlocklistItem, BlocklistResponse, Collection, Credit, DiskSpace,
|
||||
DownloadRecord, DownloadsResponse, Indexer, IndexerSettings, IndexerTestResult,
|
||||
MinimumAvailability, Monitor, Movie, MovieHistoryItem, QualityProfile, RadarrSerdeable,
|
||||
Release, SystemStatus, Tag, Task, TaskName, Update,
|
||||
RadarrTask, RadarrTaskName, Release, SystemStatus, Tag, Update,
|
||||
},
|
||||
servarr_models::{HostConfig, Log, LogResponse, QueueEvent, RootFolder, SecurityConfig},
|
||||
EnumDisplayStyle, Serdeable,
|
||||
@@ -17,7 +17,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_task_name_display() {
|
||||
assert_str_eq!(
|
||||
TaskName::ApplicationCheckUpdate.to_string(),
|
||||
RadarrTaskName::ApplicationCheckUpdate.to_string(),
|
||||
"ApplicationCheckUpdate"
|
||||
);
|
||||
}
|
||||
@@ -383,9 +383,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_radarr_serdeable_from_tasks() {
|
||||
let tasks = vec![Task {
|
||||
let tasks = vec![RadarrTask {
|
||||
name: "test".to_owned(),
|
||||
..Task::default()
|
||||
..RadarrTask::default()
|
||||
}];
|
||||
|
||||
let radarr_serdeable: RadarrSerdeable = tasks.clone().into();
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::app::radarr::radarr_context_clues::{
|
||||
};
|
||||
use crate::models::radarr_models::{
|
||||
AddMovieSearchResult, BlocklistItem, Collection, CollectionMovie, DownloadRecord,
|
||||
IndexerSettings, Movie, Task,
|
||||
IndexerSettings, Movie, RadarrTask,
|
||||
};
|
||||
use crate::models::servarr_data::radarr::modals::{
|
||||
AddMovieModal, EditCollectionModal, EditIndexerModal, EditMovieModal, IndexerTestResultModalItem,
|
||||
@@ -48,7 +48,7 @@ pub struct RadarrData<'a> {
|
||||
pub collection_movies: StatefulTable<CollectionMovie>,
|
||||
pub logs: StatefulList<HorizontallyScrollableText>,
|
||||
pub log_details: StatefulList<HorizontallyScrollableText>,
|
||||
pub tasks: StatefulTable<Task>,
|
||||
pub tasks: StatefulTable<RadarrTask>,
|
||||
pub queued_events: StatefulTable<QueueEvent>,
|
||||
pub updates: ScrollableText,
|
||||
pub main_tabs: TabState,
|
||||
|
||||
@@ -5,7 +5,7 @@ use strum::EnumIter;
|
||||
use crate::models::{
|
||||
servarr_models::{DiskSpace, Indexer, QueueEvent, RootFolder},
|
||||
sonarr_models::{
|
||||
BlocklistItem, DownloadRecord, IndexerSettings, Season, Series, SonarrHistoryItem,
|
||||
BlocklistItem, DownloadRecord, IndexerSettings, Season, Series, SonarrHistoryItem, SonarrTask,
|
||||
},
|
||||
stateful_list::StatefulList,
|
||||
stateful_table::StatefulTable,
|
||||
@@ -36,6 +36,7 @@ pub struct SonarrData {
|
||||
pub series_history: Option<StatefulTable<SonarrHistoryItem>>,
|
||||
pub start_time: DateTime<Utc>,
|
||||
pub tags_map: BiMap<i64, String>,
|
||||
pub tasks: StatefulTable<SonarrTask>,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
@@ -59,6 +60,7 @@ impl Default for SonarrData {
|
||||
series_history: None,
|
||||
start_time: DateTime::default(),
|
||||
tags_map: BiMap::default(),
|
||||
tasks: StatefulTable::default(),
|
||||
version: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ mod tests {
|
||||
assert!(sonarr_data.series_history.is_none());
|
||||
assert_eq!(sonarr_data.start_time, <DateTime<Utc>>::default());
|
||||
assert!(sonarr_data.tags_map.is_empty());
|
||||
assert!(sonarr_data.tasks.is_empty());
|
||||
assert!(sonarr_data.version.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,6 +388,44 @@ pub struct SonarrHistoryItem {
|
||||
pub data: SonarrHistoryData,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SonarrTask {
|
||||
pub name: String,
|
||||
pub task_name: SonarrTaskName,
|
||||
#[serde(deserialize_with = "super::from_i64")]
|
||||
pub interval: i64,
|
||||
pub last_execution: DateTime<Utc>,
|
||||
pub last_duration: String,
|
||||
pub next_execution: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Copy, ValueEnum)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub enum SonarrTaskName {
|
||||
#[default]
|
||||
ApplicationUpdateCheck,
|
||||
Backup,
|
||||
CheckHealth,
|
||||
CleanUpRecycleBin,
|
||||
Housekeeping,
|
||||
ImportListSync,
|
||||
MessagingCleanup,
|
||||
RefreshMonitoredDownloads,
|
||||
RefreshSeries,
|
||||
RssSync,
|
||||
UpdateSceneMapping,
|
||||
}
|
||||
|
||||
impl Display for SonarrTaskName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let task_name = serde_json::to_string(&self)
|
||||
.expect("Unable to serialize task name")
|
||||
.replace('"', "");
|
||||
write!(f, "{task_name}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||
#[serde(untagged)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
@@ -412,6 +450,7 @@ pub enum SonarrSerdeable {
|
||||
SystemStatus(SystemStatus),
|
||||
Tag(Tag),
|
||||
Tags(Vec<Tag>),
|
||||
Tasks(Vec<SonarrTask>),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
LogResponse(LogResponse),
|
||||
}
|
||||
@@ -450,6 +489,7 @@ serde_enum_from!(
|
||||
SystemStatus(SystemStatus),
|
||||
Tag(Tag),
|
||||
Tags(Vec<Tag>),
|
||||
Tasks(Vec<SonarrTask>),
|
||||
BlocklistResponse(BlocklistResponse),
|
||||
LogResponse(LogResponse),
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ mod tests {
|
||||
sonarr_models::{
|
||||
BlocklistItem, BlocklistResponse, DownloadRecord, DownloadsResponse, Episode,
|
||||
IndexerSettings, Series, SeriesStatus, SeriesType, SonarrHistoryEventType, SonarrHistoryItem,
|
||||
SonarrSerdeable, SystemStatus,
|
||||
SonarrSerdeable, SonarrTask, SonarrTaskName, SystemStatus,
|
||||
},
|
||||
EnumDisplayStyle, Serdeable,
|
||||
};
|
||||
@@ -117,6 +117,14 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_task_name_display() {
|
||||
assert_str_eq!(
|
||||
SonarrTaskName::ApplicationUpdateCheck.to_string(),
|
||||
"ApplicationUpdateCheck"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sonarr_serdeable_from() {
|
||||
let sonarr_serdeable = SonarrSerdeable::Value(json!({}));
|
||||
@@ -406,4 +414,16 @@ mod tests {
|
||||
|
||||
assert_eq!(sonarr_serdeable, SonarrSerdeable::Tags(tags));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sonarr_serdeable_from_tasks() {
|
||||
let tasks = vec![SonarrTask {
|
||||
name: "test".to_owned(),
|
||||
..SonarrTask::default()
|
||||
}];
|
||||
|
||||
let sonarr_serdeable: SonarrSerdeable = tasks.clone().into();
|
||||
|
||||
assert_eq!(sonarr_serdeable, SonarrSerdeable::Tasks(tasks));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user