Firebird/Concepts: Difference between revisions

From stonehomewiki
Jump to navigationJump to search
 
(17 intermediate revisions by the same user not shown)
Line 17: Line 17:
<div class="mw-collapsible-preview">wiring</div>
<div class="mw-collapsible-preview">wiring</div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
You can connect an output port to one ore more input port to set the data flow direction.
* You can connect an output port to one or more input ports.
* When you emit data via an output port, the data gets sends to all the input port that is connected, and the node owns those input will receive the data.
</div>
</div>
</div>
</div>
Line 23: Line 24:


= Models =
= Models =
== Node ==
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="mw-collapsible-preview">API</div>
<div class="mw-collapsible-preview">Node</div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
Represent a node in the pipeline. A node can have bunch of input ports and bunch of output ports. Each port has a unique id within the node.
Represent a node in the pipeline. A node can have bunch of input ports and bunch of output ports. Each port has a unique id within the node.
Line 53: Line 53:
<b>method: on_message</b>
<b>method: on_message</b>
<pre><nowiki>
<pre><nowiki>
on_message(self, port_name:str, data:Any)
on_message(self, port_id:str, data:Any)


Called when this node receives data. port_name is the name of the port which receive the data, data is the JSON payload of the data.
Called when this node receives data. port_id is the id of the port which receive the data, data is the JSON payload of the data.
</nowiki></pre>
</nowiki></pre>


Line 78: Line 78:
<p></p>
<p></p>


== Generator ==
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="mw-collapsible-preview">API</div>
<div class="mw-collapsible-preview">Generator</div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
Represent a node that does not have input ports.
Represent a node that does not have input ports, it is derived from Node.


<b>methods: pump</b>
<b>methods: pump</b>
Line 94: Line 93:
<p></p>
<p></p>


== Sink ==
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="mw-collapsible-preview">Sink</div>
<div class="mw-collapsible-preview">Sink</div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
Represent a node that does not have output ports.
Represent a node that does not have output ports, it is derived from Node.
</div>
</div>
</div>
</div>
Line 106: Line 104:
<div class="mw-collapsible-preview">Port</div>
<div class="mw-collapsible-preview">Port</div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
Represent a input port or output port
Represent an input port or output port of a node.


Properties:
<b>Properties</b>
* type: either PortType.INPUT or PortType.OUTPUT, represent it is a input port or output port
<pre><nowiki>
* name: name of the port, it is unique within the node
type: Either PortType.INPUT or PortType.OUTPUT, represent it is a input port or output port
* owner: the node which this port belongs to
id:   ID of the port, it is unique within the node
* connected_ports: other ports connected to this port
node: The node which this port belongs to
</nowiki></pre>


Methods:
<b>method: <nowiki>>> and <<</nowiki></b>
<pre><nowiki>
<pre><nowiki>
def connect(self, *ports: Union["Port", Node])
# connect this port to other port
# connect this port to other port
# see Node document.
</nowiki></pre>
</nowiki></pre>


<b>method: emit</b>
<pre><nowiki>
<pre><nowiki>
def emit(self, json_data:Any)
def emit(self, json_data:Any)
 
# emit JSON data to this port
# emit data to this port
</nowiki></pre>
</nowiki></pre>


Line 138: Line 136:
* A node's output port can connect to another node's input port
* A node's output port can connect to another node's input port


Properties:
<b>Properties</b>
* mq: message queue
<pre><nowiki>
* node_dict: dictionary, key is node name, value is node
id:          The id of the pipeline, every pipeline has a unique id.
title:       A human readable short description of this pipeline.
description: Detailed description of this pipeline.
mq:         RabbitMQ instance
nodes:       Containing all node belongs to this pipeline.
</nowiki></pre>


Methods:
<b>method: message_loop</b>
<pre><nowiki>
<pre><nowiki>
def message_loop(self):
def message_loop(self):
Line 149: Line 152:
</nowiki></pre>
</nowiki></pre>


<b>method: <nowiki>[]</nowiki></b>
<pre><nowiki>
<pre><nowiki>
def add_node(self, name:str, node_class, *argc, **kwargs)
# You can use [] to get node by id
 
pipeline["foo"]  # get node with id "foo" of this pipeline
# add a node to the pipeline, *argc, and **kwargs will be passed to the constructor
</nowiki></pre>
</nowiki></pre>


<pre><nowiki>
</div>
def connect(self, *, src_node_name, src_port_name=DEFAULT_PORT_NAME, dst_node_name, dst_port_name=DEFAULT_PORT_NAME)
</div>
 
<p></p>
# connect one node's output port to another node's input port
</nowiki></pre>


<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="mw-collapsible-preview">RabbitMQ</div>
<div class="mw-collapsible-content">
Represent a RabbitMQ connection
</div>
</div>
</div>
</div>
<p></p>
<p></p>


= Exception Handling =
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="toccolours mw-collapsible mw-collapsed expandable">
<div class="mw-collapsible-preview">RabbitMQ</div>
<div class="mw-collapsible-preview"></div>
<div class="mw-collapsible-content">
<div class="mw-collapsible-content">
* When you register a pipeline, 3 message queue will be created, they are
* ${pipeline_name}: all the message gets routed here
* ${pipeline_name}-error: when a message failed to process, it will be posted here, it has following fields: error_count, recent_errors: array of {failed_time, error_message}
* ${pipeline_critical}-critical: when a message failed too many times, it will be moved here.
</div>
</div>
</div>
</div>
<p></p>
<p></p>

Latest revision as of 22:46, 16 September 2023

Firebird

Overview

Models

Exception Handling