add workspace Cargo.toml and docker-compose.yml
This commit is contained in:
parent
2577edbf44
commit
c6a9b26bb2
6 changed files with 2891 additions and 0 deletions
2820
Cargo.lock
generated
Normal file
2820
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
2
Cargo.toml
Normal file
2
Cargo.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[workspace]
|
||||||
|
members = [ "datafetcher","dataworker"]
|
12
datafetcher/Cargo.toml
Normal file
12
datafetcher/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "datafetcher"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = "0.4.39"
|
||||||
|
maud = { version = "0.26.0", features = ["rocket"] }
|
||||||
|
reqwest = "0.12.12"
|
||||||
|
rocket = "0.5.1"
|
||||||
|
tokio = { version = "1.43.0", features = ["rt-multi-thread", "macros", "time"] }
|
||||||
|
dataworker = { path = "../dataworker" }
|
5
datafetcher/src/lib.rs
Normal file
5
datafetcher/src/lib.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let time_window = Duration::from_secs(3600);
|
||||||
|
}
|
42
datafetcher/src/main.rs
Normal file
42
datafetcher/src/main.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
use maud::{html, Markup};
|
||||||
|
use rocket::response::stream::{Event, EventStream};
|
||||||
|
use rocket::tokio::time::{interval, Duration};
|
||||||
|
|
||||||
|
#[get("/sse")]
|
||||||
|
async fn sse() -> EventStream![] {
|
||||||
|
EventStream! {
|
||||||
|
let mut interval = interval(Duration::from_secs(2));
|
||||||
|
loop {
|
||||||
|
interval.tick().await;
|
||||||
|
yield Event::data(format!("Updated time: {:?}", chrono::Utc::now()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
fn index() -> Markup {
|
||||||
|
html! {
|
||||||
|
html {
|
||||||
|
head {
|
||||||
|
title { "Live Updates with SSE" }
|
||||||
|
script {
|
||||||
|
"const eventSource = new EventSource('/sse');
|
||||||
|
eventSource.onmessage = (event) => {
|
||||||
|
document.getElementById('updates').innerText = event.data;
|
||||||
|
};"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
h1 { "Live Updates Example" }
|
||||||
|
div id="updates" { "Waiting for updates..." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[launch]
|
||||||
|
fn rocket() -> _ {
|
||||||
|
rocket::build().mount("/", routes![index, sse])
|
||||||
|
}
|
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
services:
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_HOST_AUTH_METHOD: trust
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
Loading…
Add table
Reference in a new issue