-
Notifications
You must be signed in to change notification settings - Fork 134
feat: add workflows #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add workflows #783
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,56 @@ | ||
| TODO | ||
|
|
||
| # Glossary | ||
|
|
||
| ## Worker | ||
|
|
||
| A process that's running workflows. | ||
|
|
||
| There are usually multiple workers running at the same time. | ||
|
|
||
| ## Workflow | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| A series of activies to be ran together. | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| The code defining a workflow only specifies what activites to be ran. There is no complex logic (e.g. database queries) running within workflows. | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Workflow code can be reran multiple times to replay a workflow. | ||
|
|
||
| ## Workflow State | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Persistated data about a workflow. | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Workflow Run | ||
|
|
||
| An instance of a node running a workflow. If re-running a workflow, it will be replaying events. | ||
|
|
||
| ## Workflow Event | ||
|
|
||
| An action that gets executed in a workflow. An event can be a: | ||
|
|
||
| - Activity | ||
|
|
||
| Events store the output from activities and are used to ensure activites are ran only once. | ||
|
|
||
| ## Workflow Event History | ||
|
|
||
| List of events that have executed in this workflow. These are used in replays to verify that the workflow has not changed to an invalid state. | ||
|
|
||
| ## Workflow Replay | ||
|
|
||
| After the first run of a workflow, all runs will replay the activities and compare against the event history. If an activity has already been ran successfully, the activity will be skipped in the replay and use the output from the previous run. | ||
|
|
||
| ## Workflow Wake Condition | ||
|
|
||
| If a workflow is not currently running an activity, wake conditions define when the workflow should be ran again. | ||
|
|
||
| The available conditions are: | ||
|
|
||
| - **Immediately** Run immediately by the first available node | ||
| - **Deadline** Run at a given timesetamp. | ||
|
|
||
| ## Activity | ||
|
|
||
| A unit of code to run within a workflow. | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Activities can fail and will be retried accoriding to the retry policy of the workflow. | ||
This file contains hidden or 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,98 @@ | ||
| ## Goals | ||
|
|
||
| **Primary** | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - Performance | ||
| - Fast to write for | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Only depend on CockroachDB | ||
|
|
||
| **Secondary** | ||
|
|
||
| - Easy to monitor & manage via simple SQL queries | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Easier to understand than messages | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Rust-native | ||
| - Run in-process and as part of the binary to simplify architecture | ||
| - Leverage traits to reduce copies and needless ser/de | ||
| - Use native serde instead of Protobuf for simplicity (**this comes at the cost of verifiable backwards compatability with protobuf**) | ||
NathanFlurry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Lay foundations for OpenGB | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Use cases | ||
|
|
||
| - Billing cron jobs with batch | ||
| - Creating servers | ||
| - Email loops | ||
| - Creating dynamic servers | ||
| - What about dynamic server lifecycle? Is this more of an actor? This is blending between state and other stuff. | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - Deploying CF workers | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Questions | ||
|
|
||
| - Concurrency | ||
| - Nondeterministic patches: https://docs.temporal.io/dev-guide/typescript/versioning#patching | ||
| - Do we plan to support side effects? | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Relation to existing Chirp primitives | ||
|
|
||
| ### Messages | ||
|
|
||
| Workflows replace the usecase of messages for durable execution, which is almost all uses of messages. | ||
|
|
||
| Messages should still be used, but much less frequently. They're helpful for: | ||
|
|
||
| **Real-time Data Processing** | ||
|
|
||
| - When you have a continuous flow of data that needs to be processed in real-time or near-real-time. | ||
| - Examples include processing sensor data, social media feeds, financial market data, or clickstream data. | ||
| - Stream processing frameworks like Apache Kafka, Apache Flink, or Apache Spark Streaming are well-suited for handling high-volume, real-time data streams. | ||
|
|
||
| **Complex Event Processing (CEP)** | ||
|
|
||
| - When you need to detect and respond to patterns, correlations, or anomalies in real-time data streams. | ||
| - CEP involves analyzing and combining multiple event streams to identify meaningful patterns or trigger actions. | ||
| - Stream processing frameworks provide capabilities for defining and matching complex event patterns in real-time. | ||
|
|
||
| **Data Transformation and Enrichment** | ||
|
|
||
| - When you need to transform, enrich, or aggregate data as it arrives in real-time. | ||
| - This can involve tasks like data cleansing, normalization, joining with other data sources, or applying machine learning models. | ||
| - Stream processing allows you to process and transform data on-the-fly, enabling real-time analytics and insights. | ||
|
|
||
| **Continuous Data Integration** | ||
|
|
||
| - When you need to continuously integrate and process data from multiple sources in real-time. | ||
| - This can involve merging data streams, performing data synchronization, or updating downstream systems. | ||
| - Stream processing frameworks provide connectors and integrations with various data sources and sinks. | ||
|
|
||
| **Real-time Monitoring and Alerting** | ||
|
|
||
| - When you need to monitor data streams in real-time and trigger alerts or notifications based on predefined conditions. | ||
| - Stream processing allows you to define rules and thresholds to detect anomalies, errors, or critical events and send real-time alerts. | ||
|
|
||
| **High-throughput, Low-latency Processing** | ||
|
|
||
| - When you have a high volume of data that needs to be processed with low latency. | ||
| - Stream processing frameworks are designed to handle high-throughput data streams and provide low-latency processing capabilities. | ||
| - This is particularly useful in scenarios like fraud detection, real-time recommendations, or real-time bidding in advertising systems. | ||
|
|
||
| ### Cross-package hooks | ||
|
|
||
| We currently use messages for hooking in to events from other workflows so we don't have to bake in support directly. | ||
|
|
||
| This is potentially error prone since it makes control flow more opaque. | ||
|
|
||
| TBD on if we keed this pattern. | ||
|
|
||
| ### Workflows & operations across packages | ||
|
|
||
| **Child workflows** | ||
|
|
||
| TODO | ||
|
|
||
| **Operations** | ||
|
|
||
| TODO | ||
|
|
||
| ## Temporal docs | ||
|
|
||
| https://docs.temporal.io/encyclopedia/ | ||
MasterPtato marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| [workspace] | ||
| members = [ | ||
| "core", | ||
| "macros" | ||
| ] |
This file contains hidden or 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,34 @@ | ||
| [package] | ||
| name = "chirp-workflow" | ||
| version = "0.1.0" | ||
| authors = ["Rivet Gaming, LLC <developer@rivet.gg>"] | ||
| edition = "2021" | ||
| license = "Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| anyhow = "1.0.82" | ||
| async-trait = "0.1.80" | ||
| chirp-client = { path = "../../chirp/client" } | ||
| chirp-workflow-macros = { path = "../macros" } | ||
| formatted-error = { path = "../../formatted-error" } | ||
| futures-util = "0.3" | ||
| global-error = { path = "../../global-error" } | ||
| indoc = "2.0.5" | ||
| prost = "0.12.4" | ||
| prost-types = "0.12.4" | ||
| rand = "0.8.5" | ||
| rivet-cache = { path = "../../cache/build" } | ||
| rivet-connection = { path = "../../connection" } | ||
| rivet-metrics = { path = "../../metrics" } | ||
| rivet-operation = { path = "../../operation/core" } | ||
| rivet-pools = { path = "../../pools" } | ||
| rivet-runtime = { path = "../../runtime" } | ||
| rivet-util = { path = "../../util/core" } | ||
| serde = { version = "1.0.198", features = ["derive"] } | ||
| serde_json = "1.0.116" | ||
| sqlx = { version = "0.7.4", features = ["runtime-tokio", "postgres", "uuid", "ipnetwork"] } | ||
| thiserror = "1.0.59" | ||
| tokio = { version = "1.37.0", features = ["full"] } | ||
| tracing = "0.1.40" | ||
| tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
| uuid = { version = "1.8.0", features = ["v4", "serde"] } |
This file contains hidden or 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,21 @@ | ||
| use std::{fmt::Debug, hash::Hash}; | ||
|
|
||
| use anyhow::*; | ||
| use async_trait::async_trait; | ||
| use serde::{de::DeserializeOwned, Serialize}; | ||
|
|
||
| use crate::ActivityCtx; | ||
|
|
||
| #[async_trait] | ||
| pub trait Activity { | ||
| type Input: ActivityInput; | ||
| type Output: Serialize + DeserializeOwned + Debug + Send; | ||
|
|
||
| fn name() -> &'static str; | ||
|
|
||
| async fn run(ctx: &mut ActivityCtx, input: &Self::Input) -> Result<Self::Output>; | ||
| } | ||
|
|
||
| pub trait ActivityInput: Serialize + DeserializeOwned + Debug + Hash + Send { | ||
| type Activity: Activity; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.