feat: make DB IDs not null
This commit is contained in:
parent
ce876955b7
commit
7965998f43
8 changed files with 175 additions and 52 deletions
|
|
@ -37,33 +37,29 @@ impl Action for BitmagnetAction {
|
|||
let mut failed_magnets = Vec::new();
|
||||
|
||||
for magnet in unprocessed_magnets {
|
||||
if let Some(id) = magnet.id {
|
||||
match self
|
||||
.client
|
||||
.submit_magnet(
|
||||
&magnet.link,
|
||||
&magnet.published_at.and_utc(),
|
||||
&magnet.imdb_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
debug!(
|
||||
"Successfully submitted magnet link to {}: {}",
|
||||
Self::name(),
|
||||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
db.mark_magnet_processed_for_table::<BitmagnetProcessedTable>(id)?;
|
||||
processed_magnets.push(magnet);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to submit magnet link to {}: {}", Self::name(), e);
|
||||
failed_magnets.push(magnet);
|
||||
}
|
||||
match self
|
||||
.client
|
||||
.submit_magnet(
|
||||
&magnet.link,
|
||||
&magnet.published_at.and_utc(),
|
||||
&magnet.imdb_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
debug!(
|
||||
"Successfully submitted magnet link to {}: {}",
|
||||
Self::name(),
|
||||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
db.mark_magnet_processed_for_table::<BitmagnetProcessedTable>(magnet.id)?;
|
||||
processed_magnets.push(magnet);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to submit magnet link to {}: {}", Self::name(), e);
|
||||
failed_magnets.push(magnet);
|
||||
}
|
||||
} else {
|
||||
warn!("Skipping magnet with null ID: {}", magnet.link);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,25 +37,21 @@ impl Action for TransmissionAction {
|
|||
let mut failed_magnets = Vec::new();
|
||||
|
||||
for magnet in unprocessed_magnets {
|
||||
if let Some(id) = magnet.id {
|
||||
match self.client.submit_magnet(&magnet.link).await {
|
||||
Ok(_) => {
|
||||
debug!(
|
||||
"Successfully submitted magnet link to {}: {}",
|
||||
Self::name(),
|
||||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
db.mark_magnet_processed_for_table::<TransmissionProcessedTable>(id)?;
|
||||
processed_magnets.push(magnet);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to submit magnet link to {}: {}", Self::name(), e);
|
||||
failed_magnets.push(magnet);
|
||||
}
|
||||
match self.client.submit_magnet(&magnet.link).await {
|
||||
Ok(_) => {
|
||||
debug!(
|
||||
"Successfully submitted magnet link to {}: {}",
|
||||
Self::name(),
|
||||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
db.mark_magnet_processed_for_table::<TransmissionProcessedTable>(magnet.id)?;
|
||||
processed_magnets.push(magnet);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to submit magnet link to {}: {}", Self::name(), e);
|
||||
failed_magnets.push(magnet);
|
||||
}
|
||||
} else {
|
||||
warn!("Skipping magnet with null ID: {}", magnet.link);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use diesel::prelude::*;
|
|||
#[diesel(table_name = magnets)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct Magnet {
|
||||
pub id: Option<i32>,
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub submitter: String,
|
||||
pub subreddit: String,
|
||||
|
|
@ -33,7 +33,7 @@ pub struct NewMagnet<'a> {
|
|||
#[diesel(table_name = bitmagnet_processed)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct BitmagnetProcessed {
|
||||
pub id: Option<i32>,
|
||||
pub id: i32,
|
||||
pub magnet_id: i32,
|
||||
pub processed_at: NaiveDateTime,
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ pub struct NewBitmagnetProcessed<'a> {
|
|||
#[diesel(table_name = transmission_processed)]
|
||||
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
|
||||
pub struct TransmissionProcessed {
|
||||
pub id: Option<i32>,
|
||||
pub id: i32,
|
||||
pub magnet_id: i32,
|
||||
pub processed_at: NaiveDateTime,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ mod tests {
|
|||
|
||||
fn create_fake_magnet() -> Magnet {
|
||||
Magnet {
|
||||
id: None,
|
||||
id: 1,
|
||||
title: "foo".to_string(),
|
||||
submitter: "bar".to_string(),
|
||||
subreddit: "baz".to_string(),
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ mod tests {
|
|||
|
||||
fn create_test_magnet(title: &str) -> Magnet {
|
||||
Magnet {
|
||||
id: Some(1),
|
||||
id: 1,
|
||||
title: title.to_string(),
|
||||
submitter: "test_user".to_string(),
|
||||
subreddit: "test_subreddit".to_string(),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
diesel::table! {
|
||||
bitmagnet_processed (id) {
|
||||
id -> Nullable<Integer>,
|
||||
id -> Integer,
|
||||
magnet_id -> Integer,
|
||||
processed_at -> Timestamp,
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ diesel::table! {
|
|||
|
||||
diesel::table! {
|
||||
magnets (id) {
|
||||
id -> Nullable<Integer>,
|
||||
id -> Integer,
|
||||
title -> Text,
|
||||
submitter -> Text,
|
||||
subreddit -> Text,
|
||||
|
|
@ -22,7 +22,7 @@ diesel::table! {
|
|||
|
||||
diesel::table! {
|
||||
transmission_processed (id) {
|
||||
id -> Nullable<Integer>,
|
||||
id -> Integer,
|
||||
magnet_id -> Integer,
|
||||
processed_at -> Timestamp,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue