diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e8d486a..30f9fce 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,6 +6,10 @@ version: 2 updates: - package-ecosystem: "cargo" # See documentation for possible values - directory: "/" # Location of package manifests + directory: "/example-app" # Location of package manifests + schedule: + interval: "weekly" + - package-ecosystem: "cargo" # See documentation for possible values + directory: "/tulsa" # Location of package manifests schedule: interval: "weekly" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2f43dd7..fb3ad62 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,11 @@ jobs: - uses: actions/checkout@v3 - name: Setup protoc uses: arduino/setup-protoc@v2.0.0 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - name: Build tulsa + run: cd tulsa && cargo build --verbose + - name: Test tulsa + run: cd tulsa && cargo test --verbose + - name: Build example-app + run: cd example-app && cargo build --verbose + - name: Test example-app + run: cd example-app && cargo test --verbose diff --git a/README.md b/README.md index 8312c5a..a6e6087 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,3 @@ -# gtfs-realtime-rust +# tulsa -This is a Rust learning exercise to build a REST server that dynamically launches and manages a set of async tasks. These tasks fetch a GTFS-Realtime feed from an endpoint supplied during a POST call. - -## Running Locally -``` -cargo test -cargo run -``` - -## Sample Feed -``` -{ - "name": "MTA A Division", - "frequency": 30, - "url": "https://api-endint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs", - "headers": { - "x-api-key": "" - } -} -``` +Learning Rust by building a scheduler for both async and sync tasks. diff --git a/Cargo.toml b/example-app/Cargo.toml similarity index 94% rename from Cargo.toml rename to example-app/Cargo.toml index 7cec019..577187e 100644 --- a/Cargo.toml +++ b/example-app/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +tulsa = { path = "../tulsa" } axum = "0.6.18" axum-macros = "0.3.7" hyper = { version = "0.14.27", features = ["client"] } diff --git a/example-app/README.md b/example-app/README.md new file mode 100644 index 0000000..8312c5a --- /dev/null +++ b/example-app/README.md @@ -0,0 +1,21 @@ +# gtfs-realtime-rust + +This is a Rust learning exercise to build a REST server that dynamically launches and manages a set of async tasks. These tasks fetch a GTFS-Realtime feed from an endpoint supplied during a POST call. + +## Running Locally +``` +cargo test +cargo run +``` + +## Sample Feed +``` +{ + "name": "MTA A Division", + "frequency": 30, + "url": "https://api-endint.mta.info/Dataservice/mtagtfsfeeds/nyct%2Fgtfs", + "headers": { + "x-api-key": "" + } +} +``` diff --git a/build.rs b/example-app/build.rs similarity index 66% rename from build.rs rename to example-app/build.rs index 618054d..1e1e4f5 100644 --- a/build.rs +++ b/example-app/build.rs @@ -1,6 +1,5 @@ extern crate prost_build; -// Helpful example from: https://github.com/danburkert/snazzy fn main() { prost_build::compile_protos(&["src/gtfs-realtime.proto"], &["src/"]).unwrap(); } diff --git a/fixtures/gtfs-07132023-123501 b/example-app/fixtures/gtfs-07132023-123501 similarity index 100% rename from fixtures/gtfs-07132023-123501 rename to example-app/fixtures/gtfs-07132023-123501 diff --git a/src/api.rs b/example-app/src/api.rs similarity index 99% rename from src/api.rs rename to example-app/src/api.rs index 98ba91a..1d59903 100644 --- a/src/api.rs +++ b/example-app/src/api.rs @@ -8,9 +8,9 @@ use axum::{ use serde::{Deserialize, Serialize}; use std::sync::{Arc, Mutex, RwLock}; use std::{collections::HashMap, sync::mpsc::{Sender, SendError}}; +use tulsa::model::{SyncTask, AsyncTask}; use crate::fetcher::{fetch_sync, Feed, recurring_fetch}; -use crate::model::{SyncTask, AsyncTask}; pub trait TaskSender { fn send(&self, task: T) -> Result<(), SendError>; diff --git a/src/deps/mime/mod.rs b/example-app/src/deps/mime/mod.rs similarity index 100% rename from src/deps/mime/mod.rs rename to example-app/src/deps/mime/mod.rs diff --git a/src/fetcher.rs b/example-app/src/fetcher.rs similarity index 100% rename from src/fetcher.rs rename to example-app/src/fetcher.rs diff --git a/src/gtfs-realtime.proto b/example-app/src/gtfs-realtime.proto similarity index 100% rename from src/gtfs-realtime.proto rename to example-app/src/gtfs-realtime.proto diff --git a/src/lib.rs b/example-app/src/lib.rs similarity index 91% rename from src/lib.rs rename to example-app/src/lib.rs index ac1e424..f20c190 100644 --- a/src/lib.rs +++ b/example-app/src/lib.rs @@ -1,7 +1,5 @@ pub mod api; pub mod fetcher; -pub mod model; -pub mod scheduler; // The deps module is an effort to re-implement my third-party dependencies as // a learning exercise. I do not plan to make this code public and my diff --git a/src/main.rs b/example-app/src/main.rs similarity index 96% rename from src/main.rs rename to example-app/src/main.rs index deeeaa9..a2460f0 100644 --- a/src/main.rs +++ b/example-app/src/main.rs @@ -1,9 +1,9 @@ use std::net::SocketAddr; use std::sync::{Arc, mpsc, Mutex}; use tokio::runtime::Builder; +use tulsa::scheduler; use gtfs_realtime_rust::api; -use gtfs_realtime_rust::scheduler; fn main() { let (sender, receiver) = mpsc::channel(); diff --git a/tests/integration_test.rs b/example-app/tests/integration_test.rs similarity index 97% rename from tests/integration_test.rs rename to example-app/tests/integration_test.rs index 8fafced..bf1c3cd 100644 --- a/tests/integration_test.rs +++ b/example-app/tests/integration_test.rs @@ -1,7 +1,6 @@ #[cfg(test)] mod tests { - use gtfs_realtime_rust::api; - use gtfs_realtime_rust::scheduler; + use tulsa::scheduler; use reqwest::blocking::Client; use serde_json::json; use std::sync::mpsc; @@ -11,6 +10,8 @@ mod tests { use std::sync::Arc; use std::sync::Mutex; + use gtfs_realtime_rust::api; + #[test] fn integration() { let (sender, receiver) = mpsc::channel(); diff --git a/tulsa/Cargo.toml b/tulsa/Cargo.toml new file mode 100644 index 0000000..86be3ad --- /dev/null +++ b/tulsa/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tulsa" +version = "0.1.0" +edition = "2021" + +[dependencies] +tokio = { version = "1.29.1", features = ["macros", "time", "rt-multi-thread"] } diff --git a/tulsa/src/lib.rs b/tulsa/src/lib.rs new file mode 100644 index 0000000..692ed62 --- /dev/null +++ b/tulsa/src/lib.rs @@ -0,0 +1,2 @@ +pub mod model; +pub mod scheduler; diff --git a/src/model.rs b/tulsa/src/model.rs similarity index 100% rename from src/model.rs rename to tulsa/src/model.rs diff --git a/src/scheduler.rs b/tulsa/src/scheduler.rs similarity index 99% rename from src/scheduler.rs rename to tulsa/src/scheduler.rs index 682e440..b883a95 100644 --- a/src/scheduler.rs +++ b/tulsa/src/scheduler.rs @@ -18,8 +18,7 @@ impl AsyncScheduler { let num_threads = 1; let runtime = Builder::new_multi_thread() - .enable_time() - .enable_io() + .enable_all() .worker_threads(num_threads) .thread_name("scheduler-runtime") .build() diff --git a/tests/scheduler_test.rs b/tulsa/tests/scheduler_test.rs similarity index 97% rename from tests/scheduler_test.rs rename to tulsa/tests/scheduler_test.rs index d977138..224b623 100644 --- a/tests/scheduler_test.rs +++ b/tulsa/tests/scheduler_test.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { - use gtfs_realtime_rust::model::AsyncTask; - use gtfs_realtime_rust::scheduler; + use tulsa::model::AsyncTask; + use tulsa::scheduler; use std::fs::File; use std::fs::OpenOptions; use std::io::prelude::*;