This commit is contained in:
Dominic Grimm 2022-12-20 19:00:12 +01:00
parent f13c9c905f
commit f614e606f4
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
15 changed files with 269 additions and 214 deletions

144
backend/Cargo.lock generated
View file

@ -273,9 +273,9 @@ dependencies = [
[[package]]
name = "addr2line"
version = "0.17.0"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
dependencies = [
"gimli",
]
@ -380,9 +380,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.66"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61"
dependencies = [
"backtrace",
]
@ -500,9 +500,9 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524"
[[package]]
name = "async-trait"
version = "0.1.59"
version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364"
checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3"
dependencies = [
"proc-macro2",
"quote",
@ -541,7 +541,6 @@ dependencies = [
"anyhow",
"celery",
"chrono",
"cookie",
"diesel",
"env_logger",
"envconfig",
@ -549,9 +548,7 @@ dependencies = [
"juniper_actix",
"lazy_static",
"log",
"reqwest",
"serde",
"serde_json",
"tikv-jemallocator",
"tokio",
"untis",
@ -560,15 +557,15 @@ dependencies = [
[[package]]
name = "backtrace"
version = "0.3.66"
version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7"
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide 0.5.4",
"miniz_oxide",
"object",
"rustc-demangle",
]
@ -702,9 +699,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.77"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d"
dependencies = [
"jobserver",
]
@ -844,9 +841,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "cookie"
version = "0.16.1"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "344adc371239ef32293cb1c4fe519592fcf21206c79c02854320afcdf3ab4917"
checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb"
dependencies = [
"percent-encoding",
"time 0.3.17",
@ -924,9 +921,9 @@ dependencies = [
[[package]]
name = "cxx"
version = "1.0.83"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf"
checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd"
dependencies = [
"cc",
"cxxbridge-flags",
@ -936,9 +933,9 @@ dependencies = [
[[package]]
name = "cxx-build"
version = "1.0.83"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39"
checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0"
dependencies = [
"cc",
"codespan-reporting",
@ -951,15 +948,15 @@ dependencies = [
[[package]]
name = "cxxbridge-flags"
version = "1.0.83"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12"
checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59"
[[package]]
name = "cxxbridge-macro"
version = "1.0.83"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6"
checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
dependencies = [
"proc-macro2",
"quote",
@ -1143,7 +1140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
dependencies = [
"crc32fast",
"miniz_oxide 0.6.2",
"miniz_oxide",
]
[[package]]
@ -1343,9 +1340,9 @@ dependencies = [
[[package]]
name = "gimli"
version = "0.26.2"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793"
[[package]]
name = "globset"
@ -1610,9 +1607,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.4"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "jobserver"
@ -1727,9 +1724,9 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
[[package]]
name = "link-cplusplus"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
@ -1807,15 +1804,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34"
dependencies = [
"adler",
]
[[package]]
name = "miniz_oxide"
version = "0.6.2"
@ -1886,19 +1874,19 @@ dependencies = [
[[package]]
name = "num_cpus"
version = "1.14.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi 0.1.19",
"hermit-abi 0.2.6",
"libc",
]
[[package]]
name = "object"
version = "0.29.0"
version = "0.30.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53"
checksum = "239da7f290cfa979f43f85a8efeee9a8a76d0827c356d37f9d3d7254d6b537fb"
dependencies = [
"memchr",
]
@ -1911,9 +1899,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
[[package]]
name = "openssl"
version = "0.10.44"
version = "0.10.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566"
checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1"
dependencies = [
"bitflags",
"cfg-if",
@ -1943,9 +1931,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.79"
version = "0.9.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4"
checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7"
dependencies = [
"autocfg",
"cc",
@ -2027,9 +2015,9 @@ dependencies = [
[[package]]
name = "paste"
version = "1.0.10"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1c2c742266c2f1041c914ba65355a83ae8747b05f208319784083583494b4b"
checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba"
[[package]]
name = "percent-encoding"
@ -2142,18 +2130,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.47"
version = "1.0.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.21"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
dependencies = [
"proc-macro2",
]
@ -2445,9 +2433,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
[[package]]
name = "schannel"
@ -2476,9 +2464,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.2"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]]
name = "sct"
@ -2515,24 +2503,24 @@ dependencies = [
[[package]]
name = "semver"
version = "1.0.14"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a"
[[package]]
name = "serde"
version = "1.0.150"
version = "1.0.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91"
checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.150"
version = "1.0.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42a3df25b0713732468deadad63ab9da1f1fd75a48a15024b50363f128db627e"
checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8"
dependencies = [
"proc-macro2",
"quote",
@ -2541,9 +2529,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.89"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
dependencies = [
"indexmap",
"itoa",
@ -2661,9 +2649,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.105"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
dependencies = [
"proc-macro2",
"quote",
@ -2707,18 +2695,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.37"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.37"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
dependencies = [
"proc-macro2",
"quote",
@ -2951,9 +2939,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]]
name = "unicode-ident"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "unicode-normalization"
@ -2982,7 +2970,7 @@ dependencies = [
[[package]]
name = "untis"
version = "0.1.0"
source = "git+https://git.dergrimm.net/dergrimm/untis.rs.git?branch=main#a6bc2bd2e947d73f18c7a118ba4836c4ea7e6531"
source = "git+https://git.dergrimm.net/dergrimm/untis.rs.git?branch=main#197b4e2ecf94bd1765593e8680008162d41a3015"
dependencies = [
"anyhow",
"chrono",
@ -3308,9 +3296,9 @@ dependencies = [
[[package]]
name = "yasna"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346d34a236c9d3e5f3b9b74563f238f955bbd05fa0b8b4efa53c130c43982f4c"
checksum = "aed2e7a52e3744ab4d0c05c20aa065258e84c49fd4226f5191b2ed29712710b4"
[[package]]
name = "zstd"

View file

@ -6,9 +6,6 @@ edition = "2021"
[[bin]]
name = "api"
[[bin]]
name = "worker"
[profile.release]
codegen-units = 1
lto = "fat"
@ -20,18 +17,15 @@ actix-cors = "0.6.4"
actix-web = "4.2.1"
anyhow = { version = "1.0.66", features = ["backtrace"] }
celery = { git = "https://github.com/rusty-celery/rusty-celery.git", branch = "main" }
chrono = { version = "0.4.23", features = ["serde"] }
cookie = "0.16.1"
chrono = "0.4.23"
diesel = { version = "2.0.2", features = ["i-implement-a-third-party-backend-and-opt-into-breaking-changes", "postgres", "chrono", "r2d2"] }
env_logger = "0.10.0"
envconfig = "0.10.0"
juniper = "0.15.10"
juniper = { version = "0.15.10", features = ["scalar-naivetime"] }
juniper_actix = "0.4.0"
lazy_static = "1.4.0"
log = "0.4.17"
reqwest = { version = "0.11.13", features = ["json"] }
serde = "1.0.148"
serde_json = "1.0.89"
tokio = { version = "1.22.0", features = ["full"] }
untis = { git = "https://git.dergrimm.net/dergrimm/untis.rs.git", branch = "main" }
url = "2.3.1"

View file

@ -7,12 +7,14 @@ COPY ./Cargo.toml ./Cargo.lock ./
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
RUN cargo install diesel_cli --no-default-features --features postgres
COPY --from=planner /usr/src/backend/recipe.json .
RUN cargo chef cook --release --recipe-path recipe.json
COPY ./src ./src
RUN cargo build --release
FROM chef as diesel
RUN cargo install diesel_cli --no-default-features --features postgres
FROM debian:buster-slim as runner
RUN apt update
RUN apt install -y libpq5
@ -21,7 +23,7 @@ RUN apt-get clean
RUN apt-get autoremove --yes
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/
WORKDIR /usr/local/bin
COPY --from=builder /usr/local/cargo/bin/diesel .
COPY --from=diesel /usr/local/cargo/bin/diesel .
WORKDIR /usr/src/backend
COPY ./run.sh .
RUN chmod +x ./run.sh

View file

@ -121,6 +121,14 @@ CREATE TABLE substitution_queries(
CREATE INDEX substitution_queries_active ON substitution_queries(active);
CREATE TABLE substitution_query_results(
id SERIAL PRIMARY KEY,
substitution_query_id INTEGER NOT NULL REFERENCES substitution_queries(id),
queried_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP
);
CREATE TYPE substitution_type AS ENUM (
'cancel',
'subst',
@ -141,7 +149,7 @@ CREATE TYPE substitution_type AS ENUM (
CREATE TABLE substitutions(
id SERIAL PRIMARY KEY,
substitution_query_id INTEGER NOT NULL REFERENCES substitution_queries(id),
substitution_query_result_id INTEGER NOT NULL REFERENCES substitution_query_results(id),
subst_type substitution_type NOT NULL,
lesson_id INTEGER NOT NULL,
start_time TIME NOT NULL,

55
backend/src/api.rs Normal file
View file

@ -0,0 +1,55 @@
// #[cfg(not(target_env = "msvc"))]
// use tikv_jemallocator::Jemalloc;
// #[cfg(not(target_env = "msvc"))]
// #[global_allocator]
// static GLOBAL: Jemalloc = Jemalloc;
// async fn graphql_route(
// req: actix_web::HttpRequest,
// payload: actix_web::web::Payload,
// schema: actix_web::web::Data<backend::graphql::Schema>,
// ) -> Result<actix_web::HttpResponse, actix_web::Error> {
// juniper_actix::graphql_handler(
// &schema,
// &backend::graphql::Context {
// pool: backend::db::POOL.clone(),
// },
// req,
// payload,
// )
// .await
// }
// #[actix_web::main]
// async fn main() -> std::io::Result<()> {
// std::env::set_var("RUST_LOG", "info");
// env_logger::init();
// let server = actix_web::HttpServer::new(move || {
// actix_web::App::new()
// .app_data(actix_web::web::Data::new(backend::graphql::schema()))
// .wrap(
// actix_cors::Cors::default()
// .allow_any_origin()
// .allowed_methods(vec!["POST", "GET"])
// .allowed_headers(vec![
// actix_web::http::header::AUTHORIZATION,
// actix_web::http::header::ACCEPT,
// ])
// .allowed_header(actix_web::http::header::CONTENT_TYPE)
// .supports_credentials()
// .max_age(3600),
// )
// .wrap(actix_web::middleware::Compress::default())
// .wrap(actix_web::middleware::Logger::default())
// .service(
// actix_web::web::resource("/")
// .route(actix_web::web::post().to(graphql_route))
// .route(actix_web::web::get().to(graphql_route)),
// )
// });
// println!("Starting server on port 80!");
// server.bind("0.0.0.0:80")?.run().await
// }

View file

@ -1,24 +1,18 @@
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
use actix_cors::Cors;
use actix_web::{
http::header,
middleware,
web::{self, Data},
App, Error, HttpResponse, HttpServer,
};
use juniper_actix::graphql_handler;
async fn graphql_route(
req: actix_web::HttpRequest,
payload: actix_web::web::Payload,
schema: actix_web::web::Data<backend::graphql::Schema>,
) -> Result<actix_web::HttpResponse, actix_web::Error> {
juniper_actix::graphql_handler(
&schema,
&backend::graphql::Context {
pool: backend::db::POOL.clone(),
},
req,
payload,
)
.await
schema: web::Data<backend::graphql::Schema>,
) -> Result<HttpResponse, Error> {
graphql_handler(&schema, &backend::graphql::Context, req, payload).await
}
#[actix_web::main]
@ -26,30 +20,25 @@ async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "info");
env_logger::init();
let server = actix_web::HttpServer::new(move || {
actix_web::App::new()
.app_data(actix_web::web::Data::new(backend::graphql::schema()))
let server = HttpServer::new(move || {
App::new()
.app_data(Data::new(backend::graphql::schema()))
.wrap(
actix_cors::Cors::default()
Cors::default()
.allow_any_origin()
.allowed_methods(vec!["POST", "GET"])
.allowed_headers(vec![
actix_web::http::header::AUTHORIZATION,
actix_web::http::header::ACCEPT,
])
.allowed_header(actix_web::http::header::CONTENT_TYPE)
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.supports_credentials()
.max_age(3600),
)
.wrap(actix_web::middleware::Compress::default())
.wrap(actix_web::middleware::Logger::default())
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::default())
.service(
actix_web::web::resource("/")
.route(actix_web::web::post().to(graphql_route))
.route(actix_web::web::get().to(graphql_route)),
web::resource("/graphql")
.route(web::post().to(graphql_route))
.route(web::get().to(graphql_route)),
)
});
println!("Starting server on port 80!");
server.bind("0.0.0.0:80")?.run().await
server.bind("0.0.0.0:80").unwrap().run().await
}

View file

@ -23,7 +23,6 @@ async fn main() {
.start()
.await
.unwrap();
println!("asdnkjndfkjlewnflj");
});
});

View file

@ -42,6 +42,8 @@ pub fn untis_from_env() -> Result<untis::Client> {
&CONFIG.untis_school,
),
client_name: CONFIG.untis_client_name.to_owned(),
user_agent: "Mozilla/5.0 (Windows NT 10.0; rv:108.0) Gecko/20100101 Firefox/108.0"
.to_string(),
username: CONFIG.untis_username.to_owned(),
password: CONFIG.untis_password.to_owned(),
session: None,

View file

@ -187,6 +187,43 @@ pub struct NewHoliday<'a> {
pub end_date: NaiveDate,
}
#[derive(Identifiable, Queryable, Associations, Debug)]
#[diesel(table_name = schema::substitution_queries)]
#[diesel(belongs_to(Schoolyear))]
pub struct SubstitutionQuery {
pub id: i32,
pub schoolyear_id: i32,
pub date: NaiveDate,
pub active: bool,
pub created_at: NaiveDateTime,
pub updated_at: Option<NaiveDateTime>,
}
#[derive(Insertable, Debug)]
#[diesel(table_name = schema::substitution_queries)]
pub struct NewSubstitutionQuery {
pub schoolyear_id: i32,
pub date: NaiveDate,
pub active: bool,
}
#[derive(Identifiable, Queryable, Associations, Debug)]
#[diesel(table_name = schema::substitution_query_results)]
#[diesel(belongs_to(SubstitutionQuery))]
pub struct SubstitutionQueryResult {
pub id: i32,
pub substitution_query_id: i32,
pub queried_at: NaiveDateTime,
pub created_at: NaiveDateTime,
pub updated_at: Option<NaiveDateTime>,
}
#[derive(Insertable, Debug)]
#[diesel(table_name = schema::substitution_query_results)]
pub struct NewSubstitutionQueryResult {
pub substitution_query_id: i32,
pub queried_at: NaiveDateTime,
}
#[derive(diesel::FromSqlRow, diesel::AsExpression, PartialEq, Eq, Debug)]
#[diesel(sql_type = schema::sql_types::SubstitutionType)]
pub enum SubstitutionType {
@ -285,38 +322,17 @@ impl From<untis::RpcSubstitionType> for SubstitutionType {
}
}
#[derive(Identifiable, Queryable, Associations, Debug)]
#[diesel(table_name = schema::substitution_queries)]
#[diesel(belongs_to(Schoolyear))]
pub struct SubstitutionQuery {
pub id: i32,
pub schoolyear_id: i32,
pub date: NaiveDate,
pub active: bool,
pub created_at: NaiveDateTime,
pub updated_at: Option<NaiveDateTime>,
}
#[derive(Insertable, Debug)]
#[diesel(table_name = schema::substitution_queries)]
pub struct NewSubstitutionQuery {
pub schoolyear_id: i32,
pub date: NaiveDate,
pub active: bool,
}
#[derive(Identifiable, Queryable, Associations, Debug)]
#[diesel(table_name = schema::substitutions)]
#[diesel(belongs_to(SubstitutionQuery))]
#[diesel(belongs_to(SubstitutionQueryResult))]
pub struct Substitution {
pub id: i32,
pub substitution_query_id: i32,
pub substitution_query_result_id: i32,
pub subst_type: SubstitutionType,
pub lesson_id: i32,
pub start_time: NaiveTime,
pub end_time: NaiveTime,
pub text: Option<String>,
pub active: bool,
pub created_at: NaiveDateTime,
pub updated_at: Option<NaiveDateTime>,
}
@ -324,7 +340,7 @@ pub struct Substitution {
#[derive(Insertable, Debug)]
#[diesel(table_name = schema::substitutions)]
pub struct NewSubstitution<'a> {
pub substitution_query_id: i32,
pub substitution_query_result_id: i32,
pub subst_type: SubstitutionType,
pub lesson_id: i32,
pub start_time: NaiveTime,

View file

@ -146,6 +146,16 @@ diesel::table! {
}
}
diesel::table! {
substitution_query_results {
id -> Integer,
substitution_query_id -> Integer,
queried_at -> Timestamp,
created_at -> Timestamp,
updated_at -> Nullable<Timestamp>,
}
}
diesel::table! {
use diesel::sql_types::*;
@ -153,7 +163,7 @@ diesel::table! {
substitutions {
id -> Integer,
substitution_query_id -> Integer,
substitution_query_result_id -> Integer,
subst_type -> SubstitutionType,
lesson_id -> Integer,
start_time -> Time,

View file

@ -1,67 +1,17 @@
use juniper::{graphql_object, EmptyMutation, EmptySubscription, FieldResult, RootNode};
use juniper::{graphql_object, EmptyMutation, EmptySubscription, GraphQLObject, RootNode};
use crate::config;
use crate::db;
#[derive(Clone, Debug)]
pub struct Context {
pub pool: db::DbPool,
}
#[derive(Clone)]
pub struct Context;
impl juniper::Context for Context {}
#[derive(Clone, Debug)]
pub struct Config;
#[graphql_object(context = Context)]
impl Config {
fn name(&self) -> &str {
"BVplan"
}
fn school(&self) -> &str {
&config::CONFIG.untis_school
}
fn version(&self) -> &str {
env!("CARGO_PKG_VERSION")
}
}
#[derive(Clone, Debug)]
pub struct Teacher {
pub id: i32,
pub display_name: String,
}
#[graphql_object(context = Context)]
impl Teacher {
fn id(&self) -> i32 {
self.id
}
fn display_name(&self) -> &str {
&self.display_name
}
}
#[derive(Clone, Copy, Debug)]
pub struct Query;
#[graphql_object(context = Context)]
impl Query {
fn ping() -> &str {
fn ping() -> &'static str {
"pong"
}
fn config() -> Config {
Config
}
async fn teachers() -> Vec<Teacher> {
vec![]
}
}
pub type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;

View file

@ -65,7 +65,7 @@ pub fn beat() -> impl std::future::Future<
tasks = [
"update_info_" => {
update_info::update_info,
schedule = DeltaSchedule::new(time::Duration::from_secs(60)),
schedule = DeltaSchedule::new(time::Duration::from_secs(5 * 60)),
args = (),
}
],

View file

@ -3,6 +3,8 @@ use celery::error::TaskError;
use celery::task::TaskResult;
use chrono::prelude::*;
use diesel::prelude::*;
use std::thread;
use std::time::Duration;
use crate::{config, db};
@ -39,7 +41,7 @@ async fn fetch_current_tenant(
schoolyear_id: i32,
) -> Result<()> {
let tenant = client.current_tenant().await?;
if diesel::select(diesel::dsl::not(diesel::expression::exists::exists(
if diesel::select(diesel::dsl::not(diesel::dsl::exists(
db::schema::tenants::table.filter(db::schema::tenants::untis_id.eq(tenant.id)),
)))
.get_result::<bool>(conn)?
@ -56,7 +58,7 @@ async fn fetch_current_tenant(
active: true,
})
.execute(conn)?;
} else if diesel::select(diesel::expression::exists::exists(
} else if diesel::select(diesel::dsl::exists(
db::schema::tenants::table
.filter(db::schema::tenants::untis_id.eq(tenant.id))
.filter(db::schema::tenants::active.eq(false)),
@ -270,7 +272,7 @@ async fn fetch_substitutions(
schoolyear_id: i32,
) -> Result<()> {
let today = Utc::now().date_naive();
if diesel::select(diesel::dsl::not(diesel::expression::exists::exists(
if diesel::select(diesel::dsl::not(diesel::dsl::exists(
db::schema::substitution_queries::table
.filter(db::schema::substitution_queries::date.eq(today)),
)))
@ -289,12 +291,19 @@ async fn fetch_substitutions(
.filter(db::schema::substitution_queries::active)
.load::<db::models::SubstitutionQuery>(conn)?
{
let now = Utc::now().naive_utc();
let query_result_id = diesel::insert_into(db::schema::substitution_query_results::table)
.values(db::models::NewSubstitutionQueryResult {
substitution_query_id: query.id,
queried_at: Utc::now().naive_utc(),
})
.returning(db::schema::substitution_query_results::id)
.get_result::<i32>(conn)?;
let substs = client.substitutions(&query.date, &query.date, None).await?;
for substitution in substs {
let substitution_id = diesel::insert_into(db::schema::substitutions::table)
.values(db::models::NewSubstitution {
substitution_query_id: query.id,
substitution_query_result_id: query_result_id,
subst_type: substitution.subst_type.into(),
lesson_id: substitution.lesson_id,
start_time: substitution.start_time,
@ -400,14 +409,19 @@ async fn fetch_substitutions(
#[celery::task]
pub async fn update_info() -> TaskResult<()> {
let dur = Duration::from_secs(10);
thread::sleep(dur);
dbg!("DONE!");
let mut client = match config::untis_from_env() {
Ok(x) => x,
Err(e) => return Err(TaskError::UnexpectedError(e.to_string())),
};
if let Err(e) = client.login().await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
let conn = &mut match db::POOL.get() {
Ok(x) => x,
@ -418,34 +432,54 @@ pub async fn update_info() -> TaskResult<()> {
Ok(x) => x,
Err(e) => return Err(TaskError::UnexpectedError(e.to_string())),
};
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_current_tenant(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_teachers(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_classes(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_subjects(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_rooms(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_departments(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_holidays(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = fetch_substitutions(&client, conn, schoolyear_id).await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
if let Err(e) = client.logout().await {
return Err(TaskError::UnexpectedError(e.to_string()));
}
thread::sleep(dur);
dbg!("DONE!");
Ok(())
}

View file

@ -3,16 +3,20 @@ events {
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
server_tokens off;
more_clear_headers Server;
server {
# location / {
# proxy_pass http://frontend/;
# }
listen 80;
location /graphql {
proxy_pass http://api/;
proxy_pass http://api:80/graphql;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;

View file

@ -64,6 +64,10 @@ services:
api:
<<: *backend
command: api
depends_on:
- postgres
- rabbitmq
- worker
volumes:
postgres: