Browse Source

Split out actors into sprinklers_actors

master
Alex Mikhalev 4 years ago
parent
commit
eff5e0c703
  1. 1
      Cargo.toml
  2. 36
      sprinklers_actors/Cargo.toml
  3. 8
      sprinklers_actors/src/lib.rs
  4. 2
      sprinklers_actors/src/program_runner.rs
  5. 16
      sprinklers_actors/src/section_runner.rs
  6. 0
      sprinklers_actors/src/trace_listeners.rs
  7. 2
      sprinklers_rs/Cargo.toml
  8. 13
      sprinklers_rs/src/main.rs
  9. 6
      sprinklers_rs/src/mqtt/mod.rs
  10. 2
      sprinklers_rs/src/mqtt/request/mod.rs
  11. 2
      sprinklers_rs/src/mqtt/request/programs.rs
  12. 2
      sprinklers_rs/src/mqtt/request/sections.rs
  13. 2
      sprinklers_rs/src/mqtt/section_runner_json.rs
  14. 5
      sprinklers_rs/src/mqtt/update_listener.rs

1
Cargo.toml

@ -3,5 +3,6 @@
members = [ members = [
"sprinklers_core", "sprinklers_core",
"sprinklers_database", "sprinklers_database",
"sprinklers_actors",
"sprinklers_rs" "sprinklers_rs"
] ]

36
sprinklers_actors/Cargo.toml

@ -0,0 +1,36 @@
[package]
name = "sprinklers_actors"
version = "0.1.0"
authors = ["Alex Mikhalev <alexmikhalevalex@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
sprinklers_core = { path = "../sprinklers_core" }
actix = { version = "0.10.0", default-features = false }
thiserror = "1.0.20"
tracing = "0.1.19"
chrono = { version = "0.4.15" }
serde = { version = "1.0.116", features = ["derive"] }
im = "15.0.0"
[dependencies.tokio]
version = "0.2.22"
default-features = false
features = []
[dependencies.futures-util]
version = "0.3.5"
default-features = false
features = ["std", "async-await", "sink"]
[dev-dependencies]
actix-rt = "1.1.1"
tokio = { version = "0.2.22", features = ["test-util"] }
assert_matches = "1.3.0"
[dev-dependencies.tracing-subscriber]
version = "0.2.11"
default-features = false
features = ["registry"]

8
sprinklers_actors/src/lib.rs

@ -0,0 +1,8 @@
pub mod program_runner;
pub mod section_runner;
#[cfg(test)]
mod trace_listeners;
pub use program_runner::ProgramRunner;
pub use section_runner::SectionRunner;

2
sprinklers_rs/src/program_runner.rs → sprinklers_actors/src/program_runner.rs

@ -485,7 +485,7 @@ mod test {
async fn test_quit() { async fn test_quit() {
let quit_msg = EventListener::new( let quit_msg = EventListener::new(
Filters::new() Filters::new()
.target("sprinklers_rs::program_runner") .target("sprinklers_actors::program_runner")
.message("program_runner stopped"), .message("program_runner stopped"),
); );
let subscriber = tracing_subscriber::registry().with(quit_msg.clone()); let subscriber = tracing_subscriber::registry().with(quit_msg.clone());

16
sprinklers_rs/src/section_runner.rs → sprinklers_actors/src/section_runner.rs

@ -62,11 +62,11 @@ pub enum SecRunState {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SecRun { pub struct SecRun {
pub(crate) handle: SectionRunHandle, pub handle: SectionRunHandle,
pub(crate) section: SectionRef, pub section: SectionRef,
pub(crate) duration: Duration, pub duration: Duration,
pub(crate) total_duration: Duration, pub total_duration: Duration,
pub(crate) state: SecRunState, pub state: SecRunState,
} }
impl SecRun { impl SecRun {
@ -94,8 +94,8 @@ pub type SecRunQueue = im::Vector<Arc<SecRun>>;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SecRunnerState { pub struct SecRunnerState {
pub(crate) run_queue: SecRunQueue, pub run_queue: SecRunQueue,
pub(crate) paused: bool, pub paused: bool,
} }
impl Default for SecRunnerState { impl Default for SecRunnerState {
@ -633,7 +633,7 @@ mod test {
async fn test_quit() { async fn test_quit() {
let quit_msg = EventListener::new( let quit_msg = EventListener::new(
Filters::new() Filters::new()
.target("sprinklers_rs::section_runner") .target("sprinklers_actors::section_runner")
.message("section_runner stopped"), .message("section_runner stopped"),
); );
let subscriber = tracing_subscriber::registry().with(quit_msg.clone()); let subscriber = tracing_subscriber::registry().with(quit_msg.clone());

0
sprinklers_rs/src/trace_listeners.rs → sprinklers_actors/src/trace_listeners.rs

2
sprinklers_rs/Cargo.toml

@ -9,6 +9,8 @@ edition = "2018"
[dependencies] [dependencies]
sprinklers_core = { path = "../sprinklers_core" } sprinklers_core = { path = "../sprinklers_core" }
sprinklers_database = { path = "../sprinklers_database" } sprinklers_database = { path = "../sprinklers_database" }
sprinklers_actors = { path = "../sprinklers_actors" }
color-eyre = "0.5.1" color-eyre = "0.5.1"
eyre = "0.6.0" eyre = "0.6.0"
thiserror = "1.0.20" thiserror = "1.0.20"

13
sprinklers_rs/src/main.rs

@ -3,16 +3,11 @@
mod mqtt; mod mqtt;
mod option_future; mod option_future;
mod program_runner;
mod section_runner;
mod section_runner_json;
#[cfg(test)]
mod trace_listeners;
mod update_listener;
use sprinklers_core::section_interface::MockSectionInterface; use sprinklers_core::section_interface::MockSectionInterface;
use sprinklers_database as database; use sprinklers_database as database;
use update_listener::UpdateListener; use sprinklers_actors as actors;
use mqtt::UpdateListener;
use eyre::Result; use eyre::Result;
use std::sync::Arc; use std::sync::Arc;
@ -39,8 +34,8 @@ async fn main() -> Result<()> {
// TODO: Section interface which actual does something. Preferrably selectable somehow // TODO: Section interface which actual does something. Preferrably selectable somehow
let section_interface: Arc<_> = MockSectionInterface::new(6).into(); let section_interface: Arc<_> = MockSectionInterface::new(6).into();
let mut section_runner = section_runner::SectionRunner::new(section_interface); let mut section_runner = actors::SectionRunner::new(section_interface);
let mut program_runner = program_runner::ProgramRunner::new(section_runner.clone()); let mut program_runner = actors::ProgramRunner::new(section_runner.clone());
let programs = database::query_programs(&conn)?; let programs = database::query_programs(&conn)?;

6
sprinklers_rs/src/mqtt/mod.rs

@ -1,12 +1,16 @@
mod actor; mod actor;
mod event_loop; mod event_loop;
mod request; mod request;
mod section_runner_json;
mod topics; mod topics;
mod update_listener;
pub use request::RequestContext; pub use request::RequestContext;
pub use update_listener::UpdateListener;
use self::topics::Topics; use self::topics::Topics;
use crate::{section_runner::SecRunnerState, section_runner_json::SecRunnerStateJson}; use section_runner_json::SecRunnerStateJson;
use sprinklers_actors::section_runner::SecRunnerState;
use sprinklers_core::model::{Program, ProgramId, Programs, Section, SectionId, Sections}; use sprinklers_core::model::{Program, ProgramId, Programs, Section, SectionId, Sections};
use actix::{Actor, Addr}; use actix::{Actor, Addr};

2
sprinklers_rs/src/mqtt/request/mod.rs

@ -1,4 +1,4 @@
use crate::{program_runner::ProgramRunner, section_runner::SectionRunner}; use sprinklers_actors::{program_runner::ProgramRunner, section_runner::SectionRunner};
use sprinklers_core::model::Sections; use sprinklers_core::model::Sections;
use futures_util::ready; use futures_util::ready;

2
sprinklers_rs/src/mqtt/request/programs.rs

@ -1,5 +1,5 @@
use super::*; use super::*;
use crate::program_runner::ProgramRunnerError; use sprinklers_actors::program_runner::ProgramRunnerError;
use sprinklers_core::model::ProgramId; use sprinklers_core::model::ProgramId;
use eyre::WrapErr; use eyre::WrapErr;

2
sprinklers_rs/src/mqtt/request/sections.rs

@ -1,5 +1,5 @@
use super::*; use super::*;
use crate::section_runner::SectionRunHandle; use sprinklers_actors::section_runner::SectionRunHandle;
use sprinklers_core::model::{self, SectionRef}; use sprinklers_core::model::{self, SectionRef};
use sprinklers_core::serde::duration_secs; use sprinklers_core::serde::duration_secs;

2
sprinklers_rs/src/section_runner_json.rs → sprinklers_rs/src/mqtt/section_runner_json.rs

@ -1,4 +1,4 @@
use crate::section_runner::{SecRun, SecRunState, SecRunnerState}; use sprinklers_actors::section_runner::{SecRun, SecRunState, SecRunnerState};
use sprinklers_core::model::SectionId; use sprinklers_core::model::SectionId;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};

5
sprinklers_rs/src/update_listener.rs → sprinklers_rs/src/mqtt/update_listener.rs

@ -1,8 +1,9 @@
use crate::{ use crate::mqtt::MqttInterface;
mqtt::MqttInterface, use sprinklers_actors::{
program_runner::{ProgramEvent, ProgramEventRecv}, program_runner::{ProgramEvent, ProgramEventRecv},
section_runner::{SecRunnerState, SecRunnerStateRecv, SectionEvent, SectionEventRecv}, section_runner::{SecRunnerState, SecRunnerStateRecv, SectionEvent, SectionEventRecv},
}; };
use actix::{fut::wrap_future, Actor, ActorContext, Addr, AsyncContext, Handler, StreamHandler}; use actix::{fut::wrap_future, Actor, ActorContext, Addr, AsyncContext, Handler, StreamHandler};
use tokio::sync::broadcast; use tokio::sync::broadcast;
use tracing::{trace, warn}; use tracing::{trace, warn};
Loading…
Cancel
Save