pub struct Graph { /* private fields */ }Expand description
A computational graph where:
- edges represent messages of static types delivered between nodes via RabbitMQ queue
- nodes represent computations that transform the input message into output message
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new<S: Into<String>>(accept_failure: S, type_error: S) -> Graph
pub fn new<S: Into<String>>(accept_failure: S, type_error: S) -> Graph
Create a new computational graph.
accept_failure : fn(Context, Error) -> Result<(), Error>type_error: Error
where:
Erroris your global error type (dge assumes that you use an global error type for your application)Contextis a data type representing the current context, this data type is defined by you, and should beFrom<T>for all of your messagesTcarried by an edge Different edges can carry different type of messages, but they all have to be serializable and deserializable by serde_json, this serialization requirement is strictly for convenience, and can be removed if there is enough motivation.
Sourcepub fn start<S: Into<String>>(&mut self, name: S) -> NodeIndex
pub fn start<S: Into<String>>(&mut self, name: S) -> NodeIndex
Represent the start of the computation.
Usually this is the first function been called to acquire a starting point for later operations after the graph is created.
Return a handle to the start node.
Sourcepub fn process<S: Into<String>>(
&mut self,
input: NodeIndex,
queue: S,
type_input: S,
name: S,
behaviour_module: S,
retry_interval_in_seconds: u32,
) -> NodeIndex
pub fn process<S: Into<String>>( &mut self, input: NodeIndex, queue: S, type_input: S, name: S, behaviour_module: S, retry_interval_in_seconds: u32, ) -> NodeIndex
Read a message of type type_input from node input via RabbitMQ queue queue,
and process it with this node, which is named name,
using behaviour defined by behaviour_module,
retry after retry_interval_in_seconds if some error happened during the processing,
(transient or non-transient), and dge decides that the processing should be retried.
Return a handle to the handler node.
Internally this will create a new node for handler,
and a new edge from input to handler representing the underlying RabbitMQ queue queue.
Sourcepub fn aggregate<S: Into<String>>(
&mut self,
inputs: Vec<NodeIndex>,
queue: S,
type_input: S,
name: S,
behaviour_module: S,
retry_interval_in_seconds: u32,
) -> NodeIndex
pub fn aggregate<S: Into<String>>( &mut self, inputs: Vec<NodeIndex>, queue: S, type_input: S, name: S, behaviour_module: S, retry_interval_in_seconds: u32, ) -> NodeIndex
Add a node that aggregate messages from inputs that belong to a single run,
and aggregate them for later consumption.
behaviour_module defines how the input messages should be aggregated.
Return a handle to the newly added node.
Sourcepub fn fan_out<S: Into<String>>(
&mut self,
input: NodeIndex,
queue: S,
type_input: S,
name: S,
retry_interval_in_seconds: u32,
) -> NodeIndex
pub fn fan_out<S: Into<String>>( &mut self, input: NodeIndex, queue: S, type_input: S, name: S, retry_interval_in_seconds: u32, ) -> NodeIndex
Create a node that will copy messages of input
to all outgoing edges of the newly created node.
Return a handle to the newly created node
Sourcepub fn poll<S: Into<String>>(
&mut self,
input: NodeIndex,
queue: S,
type_input: S,
name: S,
behaviour_module: S,
retry_interval_in_seconds: u32,
) -> NodeIndex
pub fn poll<S: Into<String>>( &mut self, input: NodeIndex, queue: S, type_input: S, name: S, behaviour_module: S, retry_interval_in_seconds: u32, ) -> NodeIndex
Add a node that polls some external system using the input message as arguments.
behaviour_module defines the function that will perform the polling,
this nodes provides scheduling for the actual polling function.
For example this can be used to query an third-party service for the availability of resource corresponding the input messages.
Sourcepub fn terminate<S: Into<String>>(
&mut self,
input: NodeIndex,
queue: S,
type_input: S,
name: S,
retry_interval_in_seconds: u32,
)
pub fn terminate<S: Into<String>>( &mut self, input: NodeIndex, queue: S, type_input: S, name: S, retry_interval_in_seconds: u32, )
An no-op node that terminates the computation.
Sourcepub fn generate<P: AsRef<Path>, S: AsRef<str>>(
self,
output_dir: P,
get_rmq_uri: S,
work_exchange: S,
retry_exchange: S,
retry_queue_prefix: S,
retry_queue_suffix: S,
init_input_queue: bool,
init_output_queue: bool,
main_init: S,
) -> Result<()>
pub fn generate<P: AsRef<Path>, S: AsRef<str>>( self, output_dir: P, get_rmq_uri: S, work_exchange: S, retry_exchange: S, retry_queue_prefix: S, retry_queue_suffix: S, init_input_queue: bool, init_output_queue: bool, main_init: S, ) -> Result<()>
Generate code represented by the graph.
- the generated code will be written to
output_dir get_rmq_uriis used to get an url to connect to the RabbitMQ serverwork_exchangeandretry_exchangeare direct RabbitMQ exchanges, for every edge in the graph, there will be a queue bound towork_exchangeto deliver the message, and a retry queue bound toretry_exchangeto handle the retry, (the retry is backed by RabbitMQ’s dead lettering mechanism)- if the
init_input_queueis true, then queues originated from starts node are also declared by theinit-exchanges-and-queuessubcommand. init_output_queuecontrols the initialization of queues leading to termination nodesmain_initis a function that will be run prior to the start of the computation, this can be used for things like setting up the logger