Skip to content

Commit

Permalink
Future proof harvest sync code for new items (#1115)
Browse files Browse the repository at this point in the history
Before this commit, when the harvest API would have returned an item
with a `kind` not known to Tobira, harvest would fail. It is expected
that a new kind, namely playlists, will be added with Opencast 16. We
will of course extend the harvest code to properly store playlists then.
This commit just makes sure that Tobira can also deal with these future
APIs without breaking.
  • Loading branch information
owi92 authored Feb 22, 2024
2 parents 89ce517 + 706555d commit 0a87dd7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ rustls = { version = "0.21.0", features = ["dangerous_configuration"] }
rustls-native-certs = "0.6.2"
rustls-pemfile = "1.0.0"
secrecy = { version = "0.8", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1"
serde_yaml = "0.9.21"
static_assertions = "1"
Expand Down
5 changes: 5 additions & 0 deletions backend/src/sync/harvest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ async fn store_in_db(
check_affected_rows_removed(rows_affected, "series", &opencast_id);
removed_series += 1;
}

HarvestItem::Unknown { kind, .. } => {
warn!("Unknown item of kind '{kind}' in harvest response. \
You might need to update Tobira.");
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions backend/src/sync/harvest/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ pub(crate) enum HarvestItem {
#[serde(with = "chrono::serde::ts_milliseconds")]
updated: DateTime<Utc>,
},

#[serde(untagged)]
Unknown {
kind: String,
#[serde(with = "chrono::serde::ts_milliseconds")]
updated: DateTime<Utc>,
},
}

impl HarvestItem {
Expand All @@ -75,6 +82,7 @@ impl HarvestItem {
Self::EventDeleted { updated, .. } => updated,
Self::Series { updated, .. } => updated,
Self::SeriesDeleted { updated, .. } => updated,
Self::Unknown { updated, .. } => updated,
}
}
}
Expand Down

0 comments on commit 0a87dd7

Please sign in to comment.