The main purpose of Zoho Circuit is to build efficient circuits in the form of workflows to coordinate multiple microservices. Circuits are state machines that can trigger and track each step automatically, and retry when there are errors.
Setting up circuits involves three steps:
- Create a Circuit
- Define a Circuit
- Builder View
- Code View
- Test a Circuit
Create a Circuit
To add a new circuit:
- Log in to the Zoho Circuit console.
- Select Circuits from the top menu bar and click +New Circuit in the top-left corner. Alternatively, you can also select +Create New in the top-right corner of homepage and select Circuits.
- Specify a unique Name for the circuit.
- Add a Description for the circuit.
- Click Create.
Define a Circuit
After circuit creation, a sample circuit with pass state as 'State 1' will be created by default, and displayed as a visual workflow under Definition.
You can define circuits in two different ways:
- Builder View
- Code View
With Builder View, you can construct your circuit as a visual workflow by dragging and dropping states from the left pane that contains Flow Controls and Functional States. Add configuration parameters for the states using the right pane with the Configuration and Input/Output settings. In Code View, create circuits with simple, predefined JSON construction.
For every change made in builder view, the equivalent JSON text is appended automatically in Code View, and vice versa. You can observe this by making a change in one view, then check it out the circuit in other view.
Builder View
Using Builder View, you can construct your state machine as a visual workflow by integrating the readily available state components and setting up their configuration. The left pane in the builder view consists of all the states that can be added to a circuit. States are building blocks of a circuit that can perform tasks, make decisions, or simply pass the output from one state to another.
States are classified into two categories:
- Flow Controls
- Functional States
Flow Controls lets you control the flow of your circuit. For example, using a flow control state called 'Pass', you can pass your input from one state to another; using state 'Success', you can stop the execution of your circuit.
Flow Controls consist the following seven states:
- Pass
- Branch
- Parallel
- Wait
- Batch
- Success
- Failure
Functional States helps you to execute business logic in circuits. You can achieve this by writing functions in the built-in editor, creating links for webhooks, or by associating a circuit within a circuit. There are three functional states:
- Function
- Webhook
- Circuit
Construct a circuit in builder view using two steps:
- Add a state
- Define a state
Add a state in Builder View
To add a state in a circuit:
- Drag and drop the state from the left pane to the visual workflow.
- Enter a unique name for the state.
- Select the Previous State and Next State between which the new state has to be added.
- Click Create.
Define a state in Builder View
To define parameters for an added state:
- Click a state in the visual workflow.
- On the right pane, under Configuration, you can optionally edit the state Name.
- The state Type is selected based on your selection by default. You can still change it in the dropdown, but the previously saved definitions, if any, will be reset.
- In the case of functional states, select the name of the Function, Webhook or Circuit to be associated with the state and define the error handling options.
- Under Input / Output, enter the Input Path, Output Path, and Result Path. To know more about I/O paths, click here.
- Click Save in the top-left menu bar.
Points to ponder
- Some state types have additional parameters. For example, the 'Wait' state contains 'duration', and the 'Batch' state includes 'Collection Path' and 'Collection Variable'. Similarly, 'Parallel' state requires 'Add Paths' and 'Branch state' needs 'Add Condition'. To know more, explore Flow Controls.
- All states except 'Success' and 'Failure' have 'Next State'. The final state of a circuit is defined by having 'Next State' value as 'End'.
- Dynamic input parameters can be added for 'Functions' using Add Parameter and for 'Webhook' using Add Parameters and Add Headers.
Working in Builder View
The following options near the left pane serve to better illustrate the visual workflow.
Click the
Zoom In icon to increase the size of the circuit.
Click the
Zoom Out icon to shrink the circuit size.
Click the
Auto-arrange icon to place the circuit in the center of the page.
Click the Change view icon to horizontally position the vertical circuit and vice versa.
Code View
In Code View, you can define your state machine in a simple JSON-based, structured language. Once a circuit is created, a sample workflow with pass state as 'State 1' is created by default.To define a circuit in Code View:
- States consist of attributes. Enter a state name. Define the attributes for the state as name value key pairs. Equivalent visual representation for the code changes can be viewed by clicking the refresh button .
- Define the common fields of the state: Name, type, and next.
- name - All the states must have a unique name to identify them within the circuit. In the circuit displayed above, 'State 1' is the name of the circuit.
- type - The actual functionality of the state is referred by its type. The following types are supported:
- pass
- branch
- parallel
- wait
- batch
- success
- failure
- function
- webhook
- circuit
- next - The name of the next state that has to be run after the completion of the current state is provided by next.
- Define the unique fields of the states. Refer to Flow Controls to explore the fields for each state.
- Provide error handling options using the 'onError' attribute for state types 'function', 'webhook', and 'circuit'.
- Specify the 'inputPath', 'outputPath', and 'resultPath' for input and output processing.
- Click Save in the top-left menu bar.
In the event of an error in JSON definition, a red cross mark [
] will be displayed beside the error line. Upon hovering on the icon, the reason for the error is displayed.
Points to ponder
- Every circuit must have one state with the field value 'start: true' to represent the beginning state.
- Each state can have only one 'next' state, except 'branch'. This is because each condition within branch must have a 'next' state.
- All states except 'success' and 'failure' must have a 'next' state. The terminal state must have the 'next' state value as 'End'.
- States can be defined in any sequence. The order of execution solely depends on the 'start' and 'next' fields.
- All fields and their values are case-sensitive. Once a value is defined, the exact value must be provided throughout the circuit.
- All the standard attribute names of the state (name keys represented in black in Code View) like type, next, duration, functionName, and collectionPath are expected in camel case.
Test a Circuit
To test your circuit:
- After saving your circuit, click Test Run in the top-left corner.
- Specify the test data as Input JSON for your test run, then click Next.
- Name your test run for this execution.
- Click Run. You can view the execution in progress. The execution run can be seen visually. To learn more about Executions, click here.
In the event of failure or data mismatch, you can repeat the execution by clicking
Run Again or
Test Run.
All the previously saved circuits and executions can be viewed using the
Versions and
Executions options.
Versions of a Circuit
Whenever a saved circuit is modified, a new version of the circuit is created. In Zoho Circuit, all the older versions are saved and can be viewed at any time. To view the all the versions of a circuit:
- Log in to the Zoho Circuit console
- Select Circuits from the top menu bar.
- Click the circuit name.
- Click the Version option from the top menu bar.
- The saved versions of the selected circuit are listed with the following details:
- Version Name
- Modified On
- Modified By
- Action
- View - Select to view the corresponding version of the circuit.
- Delete - Select to delete the chosen version of the circuit.