Skip to content

Commit

Permalink
feat(pb, ds): move to edge
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Jan 27, 2025
1 parent df8b94d commit e98ee54
Show file tree
Hide file tree
Showing 9 changed files with 765 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "edge-monolith-workflow-worker"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true

[dependencies]
chirp-workflow.workspace = true
rivet-config.workspace = true
rivet-health-checks.workspace = true
rivet-metrics.workspace = true
rivet-runtime.workspace = true

ds.workspace = true
pegboard.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use chirp_workflow::prelude::*;

pub async fn start(config: rivet_config::Config, pools: rivet_pools::Pools) -> GlobalResult<()> {
run_from_env(config, pools).await?;

Ok(())
}

#[tracing::instrument(skip_all)]
pub async fn run_from_env(
config: rivet_config::Config,
pools: rivet_pools::Pools,
) -> GlobalResult<()> {
let reg = ds::registry()?
.merge(pegboard::registry()?)?;

let db = db::DatabaseFdbSqliteNats::from_pools(pools.clone())?;
let worker = Worker::new(reg.handle(), db);

// Start worker
worker.wake_start(config, pools).await?;
bail!("worker exited unexpectedly");
}
33 changes: 33 additions & 0 deletions packages/services/edge/pegboard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "edge-pegboard"
version.workspace = true
authors.workspace = true
license.workspace = true
edition.workspace = true

[features]
default = ["workflows"]
workflows = ["chirp"]
chirp = ["chirp-workflow", "sqlx", "nix", "server-spec"]

[dependencies]
chirp-workflow = { workspace = true, optional = true }
lazy_static = "1.4"
nix = { version = "0.27", default-features = false, features = ["user", "signal"], optional = true }
rivet-config.workspace = true
rivet-metrics.workspace = true
schemars = { version = "0.8.21", features = ["url", "uuid1"] }
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.132"
strum = { version = "0.24", features = ["derive"] }
thiserror = "1.0"
util.workspace = true
uuid = "1.11.0"

pegboard.workspace = true
server-spec = { workspace = true, optional = true }

[dependencies.sqlx]
optional = true
workspace = true
features = [ "json", "ipnetwork" ]
16 changes: 16 additions & 0 deletions packages/services/edge/pegboard/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[cfg(feature = "chirp")]
use chirp_workflow::prelude::*;

#[cfg(feature = "workflows")]
pub mod workflows;

#[cfg(feature = "workflows")]
pub fn registry() -> WorkflowResult<Registry> {
use workflows::*;

let mut registry = Registry::new();
registry.register_workflow::<client::Workflow>()?;
registry.register_workflow::<actor::Workflow>()?;

Ok(registry)
}
26 changes: 26 additions & 0 deletions packages/services/edge/pegboard/src/workflows/actor/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use chirp_workflow::prelude::*;

use super::Input;

pub fn run(ctx: &mut WorkflowCtx, input: &Input) -> GlobalResult<()> {
ctx.activity(MigrateInitInput {}).await?;

Ok(())
}

#[derive(Debug, Serialize, Deserialize, Hash)]
struct MigrateInitInput {}

#[activity(MigrateInit)]
async fn migrate_init(ctx: &ActivityCtx, &MigrateInitInput) -> GlobalResult<()> {
sql_execute!(
[ctx]
"
CREATE TABLE test (
)
",
)
.await
.map_err(Into::into)
}
11 changes: 11 additions & 0 deletions packages/services/edge/pegboard/src/workflows/actor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use chirp_workflow::prelude::*;

#[derive(Debug, Serialize, Deserialize)]
pub struct Input {
pub actor_id: Uuid,
}

#[workflow]
pub async fn pegboard_actor(ctx: &mut WorkflowCtx, input: &Input) -> GlobalResult<()> {
Ok(())
}
26 changes: 26 additions & 0 deletions packages/services/edge/pegboard/src/workflows/client/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use chirp_workflow::prelude::*;

use super::Input;

pub fn run(ctx: &mut WorkflowCtx, input: &Input) -> GlobalResult<()> {
ctx.activity(MigrateInitInput {}).await?;

Ok(())
}

#[derive(Debug, Serialize, Deserialize, Hash)]
struct MigrateInitInput {}

#[activity(MigrateInit)]
async fn migrate_init(ctx: &ActivityCtx, &MigrateInitInput) -> GlobalResult<()> {
sql_execute!(
[ctx]
"
CREATE TABLE test (
)
",
)
.await
.map_err(Into::into)
}
Loading

0 comments on commit e98ee54

Please sign in to comment.