Skip to content

Commit

Permalink
Split repo into tulsa and example-app (#7)
Browse files Browse the repository at this point in the history
* Initial commit for repo split

* Update rust.yml
  • Loading branch information
tyleragreen authored Aug 28, 2023
1 parent 8c4fc40 commit a645876
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 36 deletions.
6 changes: 5 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 8 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ jobs:
- uses: actions/checkout@v3
- name: Setup protoc
uses: arduino/[email protected]
- 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
22 changes: 2 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -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": "<key_goes_here>"
}
}
```
Learning Rust by building a scheduler for both async and sync tasks.
1 change: 1 addition & 0 deletions Cargo.toml → example-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
21 changes: 21 additions & 0 deletions example-app/README.md
Original file line number Diff line number Diff line change
@@ -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": "<key_goes_here>"
}
}
```
1 change: 0 additions & 1 deletion build.rs → example-app/build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/api.rs → example-app/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
fn send(&self, task: T) -> Result<(), SendError<T>>;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions src/lib.rs → example-app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs → example-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions tulsa/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
2 changes: 2 additions & 0 deletions tulsa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod model;
pub mod scheduler;
File renamed without changes.
3 changes: 1 addition & 2 deletions src/scheduler.rs → tulsa/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/scheduler_test.rs → tulsa/tests/scheduler_test.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down

0 comments on commit a645876

Please sign in to comment.