Skip to main content

Graph

Struct Graph 

Source
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

Source

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:

  • Error is your global error type (dge assumes that you use an global error type for your application)
  • Context is a data type representing the current context, this data type is defined by you, and should be From<T> for all of your messages T carried 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.
Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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_uri is used to get an url to connect to the RabbitMQ server
  • work_exchange and retry_exchange are direct RabbitMQ exchanges, for every edge in the graph, there will be a queue bound to work_exchange to deliver the message, and a retry queue bound to retry_exchange to handle the retry, (the retry is backed by RabbitMQ’s dead lettering mechanism)
  • if the init_input_queue is true, then queues originated from starts node are also declared by the init-exchanges-and-queues subcommand.
  • init_output_queue controls the initialization of queues leading to termination nodes
  • main_init is a function that will be run prior to the start of the computation, this can be used for things like setting up the logger

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.