Skip to content

Scheduler Filestructure

Théo Tchilinguirian edited this page Sep 22, 2024 · 1 revision

File structure and modules

Explanations of the Scheduler implementation architecture.

.gitignore

Contains

/target

As to not commit compiled binaries, dependencies, and other artifacts into version control.

target/

This directory is created by cargo during cargo run Cargo is Rust's build system and package manager. It does not appear if you have not run the project

Tip: you can use cargo clean to clean remove artifacts generated by cargo from the target directory.

Cargo.lock

This file contains the state of resolved dependencies. It is generated automatically.

Cargo.toml

This file describes our dependencies, and our binary targets. The binary targets are the programs we can run. If you try to execute cargo run, the following (or similar) will display:

$ cargo run
error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
available binaries: server

It shows the available target binaries to run. You can run them with cargo run --bin <name_of_bin>.

build.rs

This script is compiled and executed by Cargo before building the package. Notably, we point to the .proto files in this script.

src/main.rs

This file contains the server. It calls the code generated by Tonic from the .proto, as well as the code for the gRPC interfaces/.

tests/

Contains integration tests to test mock data against the gRPC interfaces. Each of these tests runs the gRPC server and then runs its tests against it. To launch the server, they import modules from the scheduler package, made available by lib.rs You can run the integration tests with cargo test.

lib.rs

This file defines the modules that are publicly available / can be imported this package. They can be called using use scheduler::..., "scheduler" being the name of our crate.

The interfaces and proto modules were made public to be imported outside the crate, as they are needed in the integration tests in tests/ to launch a mock instance of the scheduler server.

src/proto/mod.rs

This module definition imports the code generated from the gRPC protos as a module to make it easier to import and use in the crate or externally.

src/interfaces/

Contains the gRPC interfaces implementation. That is, handling requests, responses, streams... There is no scheduler logic within that source code, only gRPC implementations, gRPC errors handling.

The only context known by this code is gRPC. As such, this code should not handle any other errors than gRPC errors.

This code calls the Scheduler logic implementation defined in src/logic/* All context relative to the Scheduler logic implementation (such as inputs from gRPC requests) is passed down to this code.

src/logic/

Contains the Scheduler logic implementation.

The only context known by this code is the Scheduler logic. That is its procedures, data structures... As such, this code should be handling only errors relative to the Scheduler implementation.

This code is called by the gRPC interfaces implementation defined in src/interfaces/*

Clone this wiki locally