Commit b6f44f8e authored by Ruben De Smet's avatar Ruben De Smet 🇧🇪

Get rid of pure Tokio in favour of `runtime`, await keyword.

I, for one, welcome the future!
parent cb94915d
Pipeline #67542165 passed with stage
in 10 minutes and 16 seconds
......@@ -16,7 +16,8 @@ repository = "rubdos/compass"
dotenv = "0.13.0"
edit-distance = "*"
failure = "0.1.5"
tokio-async-await = "0.1.6"
runtime = "0.3.0-alpha"
runtime-tokio = "0.3.0-alpha"
[dependencies.futures-preview]
features = ["compat"]
......@@ -35,8 +36,4 @@ path = "../radarr"
[dependencies.sonarr]
path = "../sonarr"
[dependencies.tokio]
features = ["async-await-preview"]
version = "0.1.15"
[dev-dependencies]
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]
use failure::{Error};
use futures::compat::Compat;
use sonarr::Client as SonarrClient;
use hts::Client as HtsClient;
use tokio::await;
use tokio::runtime::current_thread::Runtime;
#[runtime::main(runtime_tokio::Tokio)]
async fn main() -> Result<(), Error> {
let sonarr_server = dotenv::var("SONARR_URL").unwrap();
let api_key = dotenv::var("SONARR_API").unwrap();
async fn async_main(
sonarr: SonarrClient<String, String>,
hts: HtsClient<String, String, String>,
) -> Result<(), Error> {
let linker = await!(compass::linker::Linker::new(sonarr.clone()))?;
let hts_server = dotenv::var("HTS_URL").unwrap();
let hts_usr = dotenv::var("HTS_USERNAME").unwrap();
let hts_pwd = dotenv::var("HTS_PASSWORD").unwrap();
for recording in await!(hts.all_recordings())? {
let sonarr = SonarrClient::new(sonarr_server, api_key);
let hts = HtsClient::new(hts_server, (hts_usr, hts_pwd));
let linker = compass::linker::Linker::new(sonarr.clone()).await?;
for recording in hts.all_recordings().await? {
let (s, e) = match recording.parse_episode()? {
None => {
println!("Skipping {} -- probably not an episode ({})", recording.disp_title, recording.episode_disp);
......@@ -27,7 +31,7 @@ async fn async_main(
}
};
let series = await!(sonarr.lookup(recording.disp_title.clone()))?;
let series = sonarr.lookup(recording.disp_title.clone()).await?;
println!(" Found {} matches", series.len());
println!(" Autorec: {}", recording.autorec);
......@@ -43,19 +47,3 @@ async fn async_main(
Ok(())
}
fn main() {
let sonarr_server = dotenv::var("SONARR_URL").unwrap();
let api_key = dotenv::var("SONARR_API").unwrap();
let hts_server = dotenv::var("HTS_URL").unwrap();
let hts_usr = dotenv::var("HTS_USERNAME").unwrap();
let hts_pwd = dotenv::var("HTS_PASSWORD").unwrap();
let sonarr = SonarrClient::new(sonarr_server, api_key);
let hts = HtsClient::new(hts_server, (hts_usr, hts_pwd));
let mut rt = Runtime::new().unwrap();
let f = Compat::new(Box::pin(async_main(sonarr, hts)));
rt.block_on(f).unwrap();
}
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]
pub mod linker;
[package]
authors = ["Ruben De Smet <me@rubdos.be>"]
edition = "2018"
homepage = "https://gitlab.com/rubdos/compass/tree/master/hts"
license = "AGPL-3.0-or-later"
name = "hts"
version = "0.1.0"
readme = "README.md"
license = "AGPL-3.0-or-later"
homepage = "https://gitlab.com/rubdos/compass/tree/master/hts"
repository = "https://gitlab.com/rubdos/compass"
version = "0.1.0"
[badges]
gitlab = { repository = "rubdos/compass", branch = "master" }
[badges.gitlab]
branch = "master"
repository = "rubdos/compass"
[dependencies]
bytes = "*"
failure = "0.1.5"
log = "*"
reqwest = "0.9.10"
serde_json = "1.0.39"
tokio-async-await = "0.1.6"
runtime = "0.3.0-alpha"
runtime-tokio = "0.3.0-alpha"
[dependencies.chrono]
version = "0.4"
features = ["serde"]
version = "0.4"
[dependencies.futures-preview]
features = ["compat"]
version = "0.3.0-alpha"
[dependencies.futures_01]
package = "futures"
......@@ -29,13 +37,6 @@ version = "0.1"
features = ["derive"]
version = "1.0.89"
[dependencies.tokio]
features = ["async-await-preview"]
version = "0.1.15"
[dependencies.futures-preview]
features = ["compat"]
version = "0.3.0-alpha"
[dev-dependencies]
dotenv = "0.13.0"
env_logger = "*"
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]
mod client;
pub mod dvr;
......
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await, proc_macro_hygiene)]
use futures::compat::Compat;
use hts::Client;
use tokio::runtime::current_thread::Runtime;
macro_rules! spawn_to_result {
($e:expr) => {{
let mut rt = Runtime::new().unwrap();
let f = Compat::new(Box::pin($e));
rt.block_on(f)
}};
}
use failure::Error;
#[test]
fn list_recordings() {
#[runtime::test(runtime_tokio::Tokio)]
async fn list_recordings() -> Result<(), Error> {
let server = dotenv::var("HTS_URL").unwrap();
let username = dotenv::var("HTS_USERNAME").unwrap();
let password = dotenv::var("HTS_PASSWORD").unwrap();
......@@ -21,33 +12,31 @@ fn list_recordings() {
let client = Client::new(server, (username, password));
let recording_queries = vec![
spawn_to_result!(client.finished_recordings()),
spawn_to_result!(client.upcoming_recordings()),
spawn_to_result!(client.failed_recordings()),
spawn_to_result!(client.removed_recordings()),
client.finished_recordings().await?,
client.upcoming_recordings().await?,
client.failed_recordings().await?,
client.removed_recordings().await?,
];
let recording_queries = recording_queries.into_iter().map(|a| {
a.unwrap()
}).collect::<Vec<_>>();
let all_recordings = spawn_to_result!(client.all_recordings()).unwrap();
let all_recordings = client.all_recordings().await?;
let count: usize = recording_queries.iter().map(Vec::len).sum();
assert_eq!(count, all_recordings.len());
Ok(())
}
#[test]
fn unauthorized() {
#[runtime::test(runtime_tokio::Tokio)]
async fn unauthorized() -> Result<(), Error> {
let server = dotenv::var("HTS_URL").unwrap();
let username = "nonexistent-user";
let password = "garbage password";
let client = Client::new(server, (username, password));
let recordings = spawn_to_result!(client.finished_recordings());
let recordings = client.finished_recordings().await;
let error = recordings.expect_err("Unauthorized");
let error: hts::HtsClientError = error.downcast().expect("HtsClientError");
assert_eq!(error, hts::HtsClientError::Unauthorized);
Ok(())
}
......@@ -15,7 +15,8 @@ gitlab = { repository = "rubdos/compass", branch = "master" }
failure = "0.1.5"
reqwest = "0.9.10"
serde_json = "1.0.39"
tokio-async-await = "0.1.6"
runtime = "0.3.0-alpha"
runtime-tokio = "0.3.0-alpha"
[dependencies.echo-utils]
path = "../utils"
......@@ -32,10 +33,6 @@ version = "0.1"
features = ["derive"]
version = "1.0.89"
[dependencies.tokio]
features = ["async-await-preview"]
version = "0.1.15"
[dependencies.futures-preview]
features = ["compat"]
version = "0.3.0-alpha"
......
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]
mod client;
mod api;
......
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await, proc_macro_hygiene)]
use futures::compat::Compat;
use radarr::*;
use tokio::runtime::current_thread::Runtime;
macro_rules! spawn_to_result {
($e:expr) => {{
let mut rt = Runtime::new().unwrap();
let f = Compat::new(Box::pin($e));
rt.block_on(f)
}};
}
use failure::*;
fn default_client() -> Client<String, String> {
let server = dotenv::var("RADARR_URL").unwrap();
......@@ -19,31 +10,32 @@ fn default_client() -> Client<String, String> {
Client::new(server, api_key)
}
#[test]
fn movies() {
#[runtime::test(runtime_tokio::Tokio)]
async fn movies() -> Result<(), Error> {
let client = default_client();
let movies = spawn_to_result!(client.movies())
.unwrap();
let movies = client.movies().await?;
for movie in movies {
let _movie = spawn_to_result!(client.movie(movie.id))
.unwrap();
let _movie = client.movie(movie.id).await?;
}
Ok(())
}
#[test]
fn movie_lookup() {
#[runtime::test(runtime_tokio::Tokio)]
async fn movie_lookup() -> Result<(), Error> {
let client = default_client();
let movie = "Big Buck Bunny".into();
let candidates = spawn_to_result!(client.lookup(movie)).unwrap();
let candidates = client.lookup(movie).await?;
assert!(candidates.len() > 0);
Ok(())
}
#[test]
fn simple_get() {
#[runtime::test(runtime_tokio::Tokio)]
async fn simple_get() -> Result<(), Error> {
let client = default_client();
macro_rules! do_test {
......@@ -52,8 +44,7 @@ fn simple_get() {
};
(IMPL $method:ident) => {
println!("Testing {}", stringify!($method));
let _result = spawn_to_result!(client.$method())
.expect(stringify!($method));
let _result = client.$method().await?;
};
}
......@@ -62,16 +53,17 @@ fn simple_get() {
calendar,
movies,
}
Ok(())
}
#[test]
fn calendar_range() {
#[runtime::test(runtime_tokio::Tokio)]
async fn calendar_range() -> Result<(), Error> {
// use chrono::prelude::*;
let client = default_client();
// XXX: hard coded days
// TODO: range today to today + 1 month
let _calendar = spawn_to_result!(client.calendar_between("2019-03-30".into(), "2019-04-30".into()))
.expect("Lookup calendar");
let _calendar = client.calendar_between("2019-03-30".into(), "2019-04-30".into()).await?;
Ok(())
}
nightly-2019-02-27
nightly-2019-06-20
......@@ -15,7 +15,8 @@ gitlab = { repository = "rubdos/compass", branch = "master" }
failure = "0.1.5"
reqwest = "0.9.10"
serde_json = "1.0.39"
tokio-async-await = "0.1.6"
runtime = "0.3.0-alpha"
runtime-tokio = "0.3.0-alpha"
[dependencies.echo-utils]
path = "../utils"
......@@ -32,10 +33,6 @@ version = "0.1"
features = ["derive"]
version = "1.0.89"
[dependencies.tokio]
features = ["async-await-preview"]
version = "0.1.15"
[dependencies.futures-preview]
features = ["compat"]
version = "0.3.0-alpha"
......
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]
mod client;
mod api;
......
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await, proc_macro_hygiene)]
use futures::compat::Compat;
use sonarr::*;
use tokio::runtime::current_thread::Runtime;
macro_rules! spawn_to_result {
($e:expr) => {{
let mut rt = Runtime::new().unwrap();
let f = Compat::new(Box::pin($e));
rt.block_on(f)
}};
}
use failure::Error;
fn default_client() -> Client<String, String> {
let server = dotenv::var("SONARR_URL").unwrap();
......@@ -19,10 +10,10 @@ fn default_client() -> Client<String, String> {
Client::new(server, api_key)
}
#[test]
fn fetch_series() {
#[runtime::test(runtime_tokio::Tokio)]
async fn fetch_series() -> Result<(), Error> {
let client = default_client();
let all_series = spawn_to_result!(client.all_series()).unwrap();
let all_series = client.all_series().await?;
// Fetch every series on itself.
for series in all_series.iter() {
......@@ -30,12 +21,13 @@ fn fetch_series() {
Some(id) => id,
None => continue,
};
let _show = spawn_to_result!(client.series(id)).unwrap();
let _show = client.series(id).await?;
}
Ok(())
}
#[test]
fn simple_get() {
#[runtime::test(runtime_tokio::Tokio)]
async fn simple_get() -> Result<(), Error> {
let client = default_client();
macro_rules! do_test {
......@@ -44,8 +36,7 @@ fn simple_get() {
};
(IMPL $method:ident) => {
println!("Testing {}", stringify!($method));
let _result = spawn_to_result!(client.$method())
.expect(stringify!($method));
let _result = client.$method().await?;
};
}
......@@ -54,16 +45,17 @@ fn simple_get() {
all_series,
calendar,
}
Ok(())
}
#[test]
fn calendar_range() {
#[runtime::test(runtime_tokio::Tokio)]
async fn calendar_range() -> Result<(), Error> {
// use chrono::prelude::*;
let client = default_client();
// XXX: hard coded days
// TODO: range today to today + 1 month
let _calendar = spawn_to_result!(client.calendar_between("2019-03-30".into(), "2019-04-30".into()))
.expect("Lookup calendar");
let _calendar = client.calendar_between("2019-03-30".into(), "2019-04-30".into()).await?;
Ok(())
}
......@@ -15,16 +15,12 @@ gitlab = { repository = "rubdos/compass", branch = "master" }
failure = "0.1.5"
reqwest = "0.9.10"
serde_json = "1.0.39"
tokio-async-await = "0.1.6"
romio = "0.3.0-alpha"
[dependencies.futures_01]
package = "futures"
version = "0.1"
[dependencies.tokio]
features = ["async-await-preview"]
version = "0.1.15"
[dependencies.futures-preview]
features = ["compat"]
version = "0.3.0-alpha"
......
#![feature(await_macro, async_await, futures_api)]
#![feature(await_macro, async_await)]
use failure::Fail;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment