This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
octox now accepts a function that is called for every event that the server receives. The function takes the event, and returns a result. If the workflow succeeded, the result contains a serialize value that is used as the body of the response. If the workflow failed, an error is returned to the caller.
- Loading branch information
Showing
9 changed files
with
145 additions
and
43 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,9 +1,27 @@ | ||
use octox::{Error, Octox}; | ||
use std::sync::Arc; | ||
|
||
use github_parts::event::Event; | ||
use serde_json::Value; | ||
|
||
use octox::{Error, Octox, Workflow, WorkflowError}; | ||
|
||
#[derive(Debug)] | ||
struct HelloWorld; | ||
|
||
impl Workflow for HelloWorld { | ||
fn process(&self, event: Event) -> Result<Value, WorkflowError> { | ||
let body = format!("received {}", event).into(); | ||
|
||
println!("{}", &body); | ||
|
||
Ok(body) | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
dotenv::dotenv().ok(); | ||
|
||
let octox = Octox::new(); | ||
let octox = Octox::new().workflow(Arc::new(HelloWorld))?; | ||
octox.serve().await | ||
} |
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
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,26 @@ | ||
use axum::http::StatusCode; | ||
use axum::response::{IntoResponse, Response}; | ||
use std::fmt::Debug; | ||
|
||
use github_parts::event::Event; | ||
use thiserror::Error; | ||
|
||
pub trait Workflow: Debug + Sync + Send { | ||
fn process(&self, event: Event) -> Result<serde_json::Value, WorkflowError>; | ||
} | ||
|
||
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Error)] | ||
pub enum WorkflowError { | ||
#[error("{0}")] | ||
Unknown(String), | ||
} | ||
|
||
impl IntoResponse for WorkflowError { | ||
fn into_response(self) -> Response { | ||
match self { | ||
WorkflowError::Unknown(error) => { | ||
(StatusCode::INTERNAL_SERVER_ERROR, error).into_response() | ||
} | ||
} | ||
} | ||
} |
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,13 @@ | ||
use github_parts::event::Event; | ||
use serde_json::Value; | ||
|
||
use octox::{Workflow, WorkflowError}; | ||
|
||
#[derive(Debug)] | ||
pub struct HelloWorld; | ||
|
||
impl Workflow for HelloWorld { | ||
fn process(&self, event: Event) -> Result<Value, WorkflowError> { | ||
Ok(format!("received {}", event).into()) | ||
} | ||
} |