[−][src]Crate mcai_worker_sdk
MCAI Worker SDK
This library is an SDK to communicate via message broker with StepFlow. It's used for every worker as an abstraction. It manage itself requirements, message parsing, direct messaging.
Worker implementation
- Create a Rust project
- Add MCAI Worker SDK as a dependency in Cargo.toml:
mcai_worker_sdk = "^1.0"
- Update the main file with the example provided here to implement MessageEvent trait,
and call the
start_worker
to start the worker itself.
use mcai_worker_sdk::{ MessageEvent, Version, worker::Parameter, }; use serde_derive::Deserialize; use schemars::JsonSchema; #[derive(Debug)] struct WorkerNameEvent {} #[derive(Debug, Deserialize, JsonSchema)] struct WorkerParameters {} impl MessageEvent<WorkerParameters> for WorkerNameEvent { fn get_name(&self) -> String {"sample_worker".to_string()} fn get_short_description(&self) -> String {"Short description".to_string()} fn get_description(&self) -> String {"Long description".to_string()} fn get_version(&self) -> Version { Version::new(0, 0, 1) } } static WORKER_NAME_EVENT: WorkerNameEvent = WorkerNameEvent {}; // uncomment it to start the worker // fn main() { // mcai_worker_sdk::start_worker(&WORKER_NAME_EVENT); // }
Runtime configuration
AMQP connection
Variable | Description |
---|---|
AMQP_HOSTNAME | IP or host of AMQP server (default: localhost ) |
AMQP_PORT | AMQP server port (default: 5672 ) |
AMQP_TLS | enable secure connection using AMQPS (default: false , enable with true or 1 or TRUE or True ) |
AMQP_USERNAME | Username used to connect to AMQP server (default: guest ) |
AMQP_PASSWORD | Password used to connect to AMQP server (default: guest ) |
AMQP_VHOST | AMQP virtual host (default: / ) |
AMQP_QUEUE | AMQP queue name used to receive job orders (default: job_undefined ) |
Vault connection
Variable | Description |
---|---|
BACKEND_HOSTNAME | URL used to connect to backend server (default: http://127.0.0.1:4000/api ) |
BACKEND_USERNAME | Username used to connect to backend server |
BACKEND_PASSWORD | Password used to connect to backend server |
Start worker locally
MCAI Worker SDK can be launched locally - without RabbitMQ. It can process some message for different purpose (functional tests, message order examples, etc.).
To start worker in this mode, setup the environment variable SOURCE_ORDERS
with path(s) to json orders.
It can take multiple orders, joined with :
on unix platform, ;
on windows os.
Examples:
RUST_LOG=info SOURCE_ORDERS=./examples/success_order.json:./examples/error_order.json cargo run --example worker
Re-exports
pub use message::publish_job_progression; |
pub use parameter::container::ParametersContainer; |
pub use parameter::Parameter; |
pub use parameter::ParameterValue; |
pub use parameter::Requirement; |
Modules
job | Module to manage Job |
message | |
parameter | |
worker | Module to manage the worker |
Macros
debug | Logs a message at the debug level. |
error | Logs a message at the error level. |
info | Logs a message at the info level. |
trace | Logs a message at the trace level. |
warn | Logs a message at the warn level. |
Structs
Channel | Re-export from lapin Channel |
Version | Re-export from semver: |
Enums
MessageError | Internal error status to manage process errors |
Traits
JsonSchema | A type which can be described as a JSON Schema document. |
MessageEvent | Trait to describe a worker |
Functions
start_worker | Function to start a worker |
Type Definitions
McaiChannel | Exposed Channel type |
Result |
Derive Macros
JsonSchema |