Skip to content

Commit

Permalink
feat(all): schema 1/n
Browse files Browse the repository at this point in the history
  • Loading branch information
martsokha committed Dec 11, 2024
1 parent 720aad7 commit bd11c99
Show file tree
Hide file tree
Showing 17 changed files with 579 additions and 101 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ documentation = "https://docs.rs/axiston"

[workspace.dependencies]
axiston-rt-jsvm = { path = "./crates/jsvm", version = "0.1.0" }
axiston-rt-schema = { path = "./crates/schema", version = "0.1.0", features = ["server"] }
axiston-rt-schema = { path = "./crates/schema", version = "0.1.0" }
axiston-rt-server = { path = "./crates/server", version = "0.1.0" }
axiston-rt-task = { path = "./crates/task", version = "0.1.0" }

Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Makefile for client & server GRPC Generation
# https://github.com/hyperium/tonic

# Environment Variables
SCHEMA_OUTPUT = ./crates/schema/generated/

.PHONY: clean
clean: ## Deletes the output directory.
$(call print-info, "Cleaning project...")
rm -f $(SCHEMA_OUTPUT)
$(call print-success, "Project cleaned.")
2 changes: 2 additions & 0 deletions crates/schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ rustdoc-args = ["--cfg", "docsrs"]
path = "lib.rs"

[features]
default = ["client", "server"]

# Enables or disables gRPC client code generation.
client = []
# Enables or disables gRPC server code generation.
Expand Down
47 changes: 40 additions & 7 deletions crates/schema/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,55 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("./README.md")]

//! ### Examples
//!
//! ```rust
//! fn main() {}
//! ```
pub mod json {
//! Includes files generated by `prost`.
pub mod schema {
//! Includes files generated by `prost`.
//! Built from `jsonschema.proto`.
include!("./generated/rt.json.schema.rs");
}

pub mod value {
//! Includes files generated by `prost`.
//! Built from `jsonvalue.proto`.
include!("./generated/rt.json.value.rs");
}
}

pub mod instance {
//! Includes files generated by `prost`.
//! Built from `instance.proto`.
include!("./generated/instance.rs");
include!("./generated/rt.instance.rs");
}

pub mod registry {
//! Includes files generated by `prost`.
//! Built from `registry.proto`.
include!("./generated/registry.rs");
include!("./generated/rt.registry.rs");
}

pub mod entity {
//! Includes files generated by `prost`.
//! Built from `entity.proto`.
include!("./generated/rt.entity.rs");
}

pub mod request {
//! Includes files generated by `prost`.
//! Built from `request.proto`.
include!("./generated/rt.request.rs");
}

pub mod response {
//! Includes files generated by `prost`.
//! Built from `response.proto`.
include!("./generated/rt.response.rs");
}
82 changes: 82 additions & 0 deletions crates/schema/protobuf/entity.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "internal/jsonschema.proto";
import "internal/jsonvalue.proto";

package rt.entity;

// Describes service details.
message Service {
// Unique identifier for the service.
string service_id = 1;
// Name of the service (e.g., Google Email).
string name = 21;
// Unique identifier for the service's icon.
string icon = 22;
// Brief description of the service.
string description = 4;
}

// Describes action or trigger details.
message Entity {
string entity_id = 1;
string service_id = 2;

string name = 21;
string icon = 22;

// Input specifications for this entity.
repeated Input inputs = 7;
// Output specifications for this entity.
repeated Output outputs = 8;
// Possible error codes this entity might return.
repeated Error errors = 9;
}

// Describes secrets required by a entity.
message Secret {
// Unique identifier for the secret.
string id = 1;
// Name of the secret (e.g., "API Key").
string name = 2;
// Description of the secret.
string description = 3;
// Whether the secret is mandatory for the service.
bool is_required = 4;
}

// Describes the input requirements for an entity.
message Input {
// Name of the input (e.g., "recipient").
string name = 1;
// Data type of the input (e.g., "string", "int").
rt.json.schema.JsonSchema data_type = 2;
// Description of the input.
string description = 3;
// Whether this input is mandatory.
bool is_required = 4;
// Default value for the input, if applicable.
rt.json.value.JsonValue default_value = 5;
}

// Describes the output generated by an entity.
message Output {
// Name of the output (e.g., "message_id").
string name = 1;
// Data type of the output (e.g., "string", "int").
rt.json.schema.JsonSchema data_type = 2;
// Description of the output.
string description = 3;
}

// Describes potential errors an entity can return.
message Error {
// Unique error code (e.g., "ERR_401").
string code = 1;
// Human-readable error message.
string message = 2;
// Description or guidance for resolving the error.
string resolution = 3;
}
99 changes: 99 additions & 0 deletions crates/schema/protobuf/event/request.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";

package rt.request;

// Request to open a connection to the event bus.
// Indicates the Gateway is ready accept events.
message OpenRequest {
// Token for authenticating the Gateway.
string authentication_token = 3;
// Required runtime capabilities.
repeated string runtime_capabilities = 4;
// Preferred communication protocols.
repeated string preferred_protocols = 5;

// Constraints on resources for the task.
optional ResourceLimits resource_limits = 26;
}

// Request to submit a task for execution by the Runtime.
message ExecuteRequest {
// Unique identifier for the task.
string task_id = 1;
// Custom task parameters as key-value pairs.
map<string, string> task_fields = 2;
// Sensitive task-specific data (e.g., API keys).
map<string, string> task_secrets = 3;

// Priority level of the task (higher is more important).
optional int32 priority = 23;
// Deadline for the task completion.
optional google.protobuf.Timestamp deadline = 24;
// Whether task dependencies are cached.
optional bool cache_deps = 25;

// Policy for retrying failed tasks.
optional RetryPolicy retry_policy = 31;
// Policy for handling task timeouts.
optional TimeoutPolicy timeout_policy = 32;
}

// Request to close the connection, preventing the Runtime from accepting new tasks.
message CloseRequest {
// Force immediate closure without waiting.
// Ignores pending tasks (from this connection) before closing.
optional bool force_close = 2;
// Reason for closing the connection.
optional string reason = 3;
// Require acknowledgment before closing.
optional bool ack_required = 4;
}

// Policy for retrying failed tasks.
message RetryPolicy {
// Maximum number of retry attempts.
uint32 max_retries = 1;
// Base delay between consecutive retries.
google.protobuf.Duration base_backoff = 2;
// Multiplier for exponential backoff.
optional double exponential_multiplier = 3;
// Maximum delay between consecutive retries.
google.protobuf.Duration max_backoff = 4;
}

// Policy for handling task timeouts.
message TimeoutPolicy {
// Maximum execution time allowed for the task.
google.protobuf.Duration execution_timeout = 1;
// Whether to forcibly terminate the task on timeout.
bool terminate_on_timeout = 2;
// Action to take on timeout (e.g., "retry", "terminate").
TimeoutAction timeout_action = 3;
// Extra time given before final termination after timeout.
optional google.protobuf.Duration grace_period = 4;
// Frequency of checking for timeout conditions.
optional google.protobuf.Duration monitor_interval = 5;
}

// Lists all of possible timeout actions.
enum TimeoutAction {
// Default value, action unspecified.
TIMEOUT_ACTION_UNSPECIFIED = 0;
// Task is considered to be failed. Retry the task.
TIMEOUT_ACTION_RETRY = 1;
// Task is considered to be failed. Do not retry the task.
TIMEOUT_ACTION_TERMINATE = 2;
}

// Limits runtime resources.
message ResourceLimits {
// Maximum used CPU percentage.
uint32 max_cpu_percent = 1;
// Maximum used RAM in MB.
uint32 max_ram_mb = 2;
// Maximum used disk in MB.
uint64 max_disk_mb = 3;
}
Loading

0 comments on commit bd11c99

Please sign in to comment.