This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #501 from freeflowuniverse/development_openapi
Development openapi
- Loading branch information
Showing
40 changed files
with
3,410 additions
and
283 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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,33 @@ | ||
module processor | ||
|
||
// ProcedureError struct for error handling | ||
pub struct ProcedureError { | ||
reason ErrorReason | ||
} | ||
|
||
// Enum for different error reasons | ||
pub enum ErrorReason { | ||
timeout | ||
serialization_failed | ||
deserialization_failed | ||
enqueue_failed | ||
} | ||
|
||
pub fn (err ProcedureError) code() int { | ||
return match err.reason { | ||
.timeout { 408 } // HTTP 408 Request Timeout | ||
.serialization_failed { 500 } // HTTP 500 Internal Server Error | ||
.deserialization_failed { 500 } // HTTP 500 Internal Server Error | ||
.enqueue_failed { 503 } // HTTP 503 Service Unavailable | ||
} | ||
} | ||
|
||
pub fn (err ProcedureError) msg() string { | ||
explanation := match err.reason { | ||
.timeout { 'The procedure call timed out.' } | ||
.serialization_failed { 'Failed to serialize the procedure call.' } | ||
.deserialization_failed { 'Failed to deserialize the procedure response.' } | ||
.enqueue_failed { 'Failed to enqueue the procedure response.' } | ||
} | ||
return 'Procedure failed: $explanation' | ||
} |
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,15 @@ | ||
module processor | ||
|
||
// ProcedureCall struct representing a procedure invocation | ||
pub struct ProcedureCall { | ||
pub: | ||
method string // Method name (derived from OpenAPI path) | ||
params string // Parameters for the procedure | ||
} | ||
|
||
// ProcedureResponse struct representing the result of a procedure call | ||
pub struct ProcedureResponse { | ||
pub: | ||
result string // Response data | ||
error string // Internal error message (if any) | ||
} |
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,42 @@ | ||
module processor | ||
|
||
import json | ||
import freeflowuniverse.crystallib.clients.redisclient | ||
|
||
// Processor struct for managing procedure calls | ||
pub struct Processor { | ||
pub mut: | ||
rpc redisclient.RedisRpc // Redis RPC mechanism | ||
} | ||
|
||
// Parameters for processing a procedure call | ||
@[params] | ||
pub struct ProcessParams { | ||
pub: | ||
timeout int // Timeout in seconds | ||
} | ||
|
||
// Process the procedure call | ||
pub fn (mut p Processor) process(call ProcedureCall, params ProcessParams) !ProcedureResponse { | ||
// Use RedisRpc's `call` to send the call and wait for the response | ||
response_data := p.rpc.call(redisclient.RPCArgs{ | ||
cmd: call.method | ||
data: call.params | ||
timeout: u64(params.timeout * 1000) // Convert seconds to milliseconds | ||
wait: true | ||
}) or { | ||
// TODO: check error type | ||
return ProcedureResponse{ | ||
error: err.msg() | ||
} | ||
// return ProcedureError{ | ||
// reason: .timeout | ||
// } | ||
} | ||
|
||
println('resp data ${response_data}') | ||
|
||
return ProcedureResponse{ | ||
result: response_data | ||
} | ||
} |
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
Oops, something went wrong.