Skip to content

Commit

Permalink
feat(filters): started match pattern filter
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobressan committed Aug 16, 2023
1 parent 3fd308a commit 98cca15
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/filters/match_pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use gasket::framework::*;
use serde::Deserialize;

use crate::framework::*;

#[derive(Default, Stage)]
#[stage(name = "filter-match-pattern", unit = "ChainEvent", worker = "Worker")]
pub struct Stage {
pub input: FilterInputPort,
pub output: FilterOutputPort,

#[metric]
ops_count: gasket::metrics::Counter,
}

#[derive(Default)]
pub struct Worker;

impl From<&Stage> for Worker {
fn from(_: &Stage) -> Self {
Worker::default()
}
}

gasket::impl_mapper!(|_worker: Worker, stage: Stage, unit: ChainEvent| => {
let out = unit.clone();
stage.ops_count.inc(1);
out
});

#[derive(Default, Deserialize)]
pub struct Config {}

impl Config {
pub fn bootstrapper(self, _ctx: &Context) -> Result<Stage, Error> {
Ok(Stage::default())
}
}
7 changes: 7 additions & 0 deletions src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod deno;
pub mod dsl;
pub mod json;
pub mod legacy_v1;
pub mod match_pattern;
pub mod noop;
pub mod parse_cbor;
pub mod split_block;
Expand All @@ -24,6 +25,7 @@ pub enum Bootstrapper {
Wasm(wasm::Stage),
Deno(deno::Stage),
ParseCbor(parse_cbor::Stage),
MatchPattern(match_pattern::Stage),
}

impl StageBootstrapper for Bootstrapper {
Expand All @@ -37,6 +39,7 @@ impl StageBootstrapper for Bootstrapper {
Bootstrapper::Wasm(p) => p.input.connect(adapter),
Bootstrapper::Deno(p) => p.input.connect(adapter),
Bootstrapper::ParseCbor(p) => p.input.connect(adapter),
Bootstrapper::MatchPattern(p) => p.input.connect(adapter),
}
}

Expand All @@ -50,6 +53,7 @@ impl StageBootstrapper for Bootstrapper {
Bootstrapper::Wasm(p) => p.output.connect(adapter),
Bootstrapper::Deno(p) => p.output.connect(adapter),
Bootstrapper::ParseCbor(p) => p.output.connect(adapter),
Bootstrapper::MatchPattern(p) => p.output.connect(adapter),
}
}

Expand All @@ -63,6 +67,7 @@ impl StageBootstrapper for Bootstrapper {
Bootstrapper::Wasm(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::Deno(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::ParseCbor(x) => gasket::runtime::spawn_stage(x, policy),
Bootstrapper::MatchPattern(x) => gasket::runtime::spawn_stage(x, policy),
}
}
}
Expand All @@ -78,6 +83,7 @@ pub enum Config {
Wasm(wasm::Config),
Deno(deno::Config),
ParseCbor(parse_cbor::Config),
MatchPattern(match_pattern::Config),
}

impl Config {
Expand All @@ -91,6 +97,7 @@ impl Config {
Config::Wasm(c) => Ok(Bootstrapper::Wasm(c.bootstrapper(ctx)?)),
Config::Deno(c) => Ok(Bootstrapper::Deno(c.bootstrapper(ctx)?)),
Config::ParseCbor(c) => Ok(Bootstrapper::ParseCbor(c.bootstrapper(ctx)?)),
Config::MatchPattern(c) => Ok(Bootstrapper::MatchPattern(c.bootstrapper(ctx)?)),
}
}
}
Expand Down

0 comments on commit 98cca15

Please sign in to comment.