-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ade5d1
commit 1e61454
Showing
10 changed files
with
1,159 additions
and
2 deletions.
There are no files selected for viewing
775 changes: 775 additions & 0 deletions
775
typegate/tests/runtimes/temporal/__snapshots__/temporal_test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typegraph_next import t, typegraph, Policy, Graph | ||
from typegraph_next.providers.temporal import TemporalRuntime | ||
|
||
|
||
@typegraph() | ||
def temporal(g: Graph): | ||
public = Policy.public() | ||
temporal = TemporalRuntime("<name>", "<host>") | ||
arg = t.struct({"some_field": t.string()}) | ||
|
||
g.expose( | ||
public, | ||
start=temporal.start_workflow("<workflow_type>", arg), | ||
query=temporal.query_workflow("<query_type>", arg), | ||
signal=temporal.signal_workflow("<signal_name>", arg), | ||
describe=temporal.describe_workflow(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Metatype OÜ, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
import { Policy, t, typegraph } from "@typegraph/deno/src/mod.ts"; | ||
import { TemporalRuntime } from "@typegraph/deno/src/providers/temporal.ts"; | ||
|
||
typegraph("temporal", (g) => { | ||
const pub = Policy.public(); | ||
const temporal = new TemporalRuntime("<name>", "<host>"); | ||
const arg = t.struct({ some_field: t.string() }); | ||
|
||
g.expose( | ||
{ | ||
start: temporal.startWorkflow("<workflow_type>", arg).withPolicy(pub), | ||
query: temporal.queryWorkflow("<query_type>", arg).withPolicy(pub), | ||
signal: temporal.signalWorkflow("<signal_name>", arg).withPolicy(pub), | ||
describe: temporal.describeWorkflow().withPolicy(pub), | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright Metatype OÜ, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
|
||
import { Meta } from "../../utils/mod.ts"; | ||
import { MetaTest } from "../../utils/test.ts"; | ||
|
||
async function testSerialize(t: MetaTest, file: string) { | ||
await t.should(`serialize typegraph ${file}`, async () => { | ||
const tg = await Meta.cli("serialize", "--pretty", "-f", file); | ||
await t.assertSnapshot(tg); | ||
}); | ||
} | ||
|
||
Meta.test("Typegraph using temporal", async (t) => { | ||
await testSerialize(t, "runtimes/temporal/temporal.py"); | ||
await testSerialize(t, "runtimes/temporal/temporal.ts"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use super::Materializer; | ||
use crate::errors::Result; | ||
use crate::global_store::with_store_mut; | ||
use crate::t; | ||
use crate::t::TypeBuilder; | ||
use crate::wit::core::TypeId; | ||
use crate::wit::runtimes::Effect as WitEffect; | ||
use crate::wit::runtimes::{RuntimeId, TemporalOperationData, TemporalOperationType}; | ||
|
||
#[derive(Debug)] | ||
pub enum TemporalMaterializer { | ||
Start { workflow_type: String }, | ||
Signal { signal_name: String }, | ||
Query { query_type: String }, | ||
Describe, | ||
} | ||
|
||
pub fn temporal_operation(runtime: RuntimeId, data: TemporalOperationData) -> Result<TypeId> { | ||
let mut inp = t::struct_(); | ||
let (effect, mat_data) = match data.operation { | ||
TemporalOperationType::StartWorkflow => { | ||
let arg = data | ||
.func_arg | ||
.ok_or("workflow arg is undefined".to_string())?; | ||
let mat_arg = data | ||
.mat_arg | ||
.ok_or("materializer arg is undefined".to_string())?; | ||
inp.prop("workflow_id", t::string().build()?); | ||
inp.prop("args", t::array(arg.into()).build()?); | ||
( | ||
WitEffect::Create(false), | ||
TemporalMaterializer::Start { | ||
workflow_type: mat_arg, | ||
}, | ||
) | ||
} | ||
TemporalOperationType::SignalWorkflow => { | ||
let arg = data | ||
.func_arg | ||
.ok_or("workflow arg is undefined".to_string())?; | ||
let mat_arg = data | ||
.mat_arg | ||
.ok_or("materializer arg is undefined".to_string())?; | ||
inp.prop("workflow_id", t::string().build()?); | ||
inp.prop("run_id", t::string().build()?); | ||
inp.prop("args", t::array(arg.into()).build()?); | ||
( | ||
WitEffect::Update(false), | ||
TemporalMaterializer::Signal { | ||
signal_name: mat_arg, | ||
}, | ||
) | ||
} | ||
TemporalOperationType::QueryWorkflow => { | ||
let arg = data | ||
.func_arg | ||
.ok_or("workflow arg is undefined".to_string())?; | ||
let mat_arg = data | ||
.mat_arg | ||
.ok_or("materializer arg is undefined".to_string())?; | ||
inp.prop("workflow_id", t::string().build()?); | ||
inp.prop("run_id", t::string().build()?); | ||
inp.prop("args", t::array(arg.into()).build()?); | ||
( | ||
WitEffect::None, | ||
TemporalMaterializer::Query { | ||
query_type: mat_arg, | ||
}, | ||
) | ||
} | ||
TemporalOperationType::DescribeWorkflow => { | ||
inp.prop("workflow_id", t::string().build()?); | ||
inp.prop("run_id", t::string().build()?); | ||
(WitEffect::None, TemporalMaterializer::Describe) | ||
} | ||
}; | ||
|
||
let mat = Materializer::temporal(runtime, mat_data, effect); | ||
let mat_id = with_store_mut(|s| s.register_materializer(mat)); | ||
let fn_id = t::func(inp.build()?, t::string().build()?, mat_id)?; | ||
Ok(fn_id.into()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.