Skip to content

Commit

Permalink
feat: create a waker
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 18, 2022
1 parent cce2b03 commit 6cd25fd
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 11 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"core",
"injector",
"processor",
"waker",
"server",
]
exclude = [
Expand Down
25 changes: 16 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ RUN \

RUN ls /output

FROM ghcr.io/drogue-iot/diesel-base:0.2.0 as database-migration

LABEL org.opencontainers.image.source="https://github.com/drogue-iot/drogue-doppelgaenger"

RUN mkdir /migrations
COPY database-migration/migrations /migrations

ENTRYPOINT ["/usr/local/bin/diesel"]

ENV RUST_LOG "diesel=debug"

CMD ["migration", "run"]

FROM registry.access.redhat.com/ubi9-minimal AS base

RUN microdnf install -y libpq
Expand Down Expand Up @@ -49,16 +62,10 @@ LABEL org.opencontainers.image.source="https://github.com/drogue-iot/drogue-dopp
COPY --from=builder /output/drogue-doppelgaenger-server /
ENTRYPOINT [ "/drogue-doppelgaenger-server" ]


FROM ghcr.io/drogue-iot/diesel-base:0.2.0 as database-migration
FROM base AS waker

LABEL org.opencontainers.image.source="https://github.com/drogue-iot/drogue-doppelgaenger"

RUN mkdir /migrations
COPY database-migration/migrations /migrations
COPY --from=builder /output/drogue-doppelgaenger-waker /
ENTRYPOINT [ "/drogue-doppelgaenger-waker" ]

ENTRYPOINT ["/usr/local/bin/diesel"]

ENV RUST_LOG "diesel=debug"

CMD ["migration", "run"]
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ MODULES= \
processor \
server \
database-migration \
waker \


#
Expand Down
6 changes: 4 additions & 2 deletions core/src/waker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::{
service::Id,
};
use async_trait::async_trait;
use std::future::Future;
use serde::de::DeserializeOwned;
use std::{fmt::Debug, future::Future};

#[derive(Clone, Debug)]
pub struct TargetId {
Expand All @@ -17,7 +18,7 @@ pub struct TargetId {

#[async_trait]
pub trait Waker: Sized + Send + Sync {
type Config;
type Config: Clone + Debug + DeserializeOwned;

fn from_config(config: Self::Config) -> anyhow::Result<Self>;

Expand All @@ -31,6 +32,7 @@ pub trait Waker: Sized + Send + Sync {
Fut: Future<Output = anyhow::Result<()>> + Send;
}

#[derive(Debug, serde::Deserialize)]
pub struct Config<W: Waker, S: Sink> {
pub waker: W::Config,
pub sink: S::Config,
Expand Down
18 changes: 18 additions & 0 deletions waker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "drogue-doppelgaenger-waker"
description = "Drogue IoT Doppelgänger Waker"
version = "0.1.0"
authors = ["Jens Reimann <[email protected]>"]
edition = "2021"
license = "Apache-2.0"

[dependencies]
anyhow = "1"
drogue-bazaar = "0.2"
env_logger = "0.9"
futures = "0.3"
log = "0.4"
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["full"] }

drogue-doppelgaenger-core = { path = "../core" }
16 changes: 16 additions & 0 deletions waker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use drogue_bazaar::app::{Startup, StartupExt};
use drogue_doppelgaenger_core::{
processor::sink::{self},
waker::{self, Config},
};

pub async fn run(
config: Config<waker::postgres::Waker, sink::kafka::Sink>,
startup: &mut dyn Startup,
) -> anyhow::Result<()> {
let waker = waker::Processor::from_config(config)?.run();

startup.spawn(waker);

Ok(())
}
8 changes: 8 additions & 0 deletions waker/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use drogue_bazaar::runtime;
use drogue_doppelgaenger_core::PROJECT;
use drogue_doppelgaenger_waker::run;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
runtime!(PROJECT).exec_fn(run).await
}

0 comments on commit 6cd25fd

Please sign in to comment.