Basic idea of how to use Flor gem.

Basic idea of how to use Flor gem.

27 Jul 2021
0 Comments
Basic idea of how to use Flor gem.

As a workflow engine, flor takes in input process definitions and executes them. These executions, in turn, call pieces of Ruby code or external scripts to perform the actual work. Those pieces of code and scripts are referred to as "taskers".

 

The flor workflow engine can be created as follows by installing the gem ‘flor/unit’ and asking the flor library inside the ruby file.

 

1) Add the command to your gem file:

gem ‘flor’

 

2) Run: bundle update.

 

3) Use the basic control-flow pattern in flor.

  • Sequence / cursor.
  • Parallel Split.
  • Synchronization.

 

4) Create a ruby file and add this code to it.

 

5) "Require flor" gem for using them in the entire program file.

 

flor-gem

 

6) Database connection:

The database is used to store the execution process. The user can use MySQL, PostgreSQL, and SQLite DB. The sequel does not support the MongoDB adapter.

 

  • Use the below-mentioned syntax while using the SQLite database.

 

flor-gem-sqlite

 

  • Use this syntax while using the MySQL database.

 

flor-gem-user

 

7) Starting and launching the flor unit execution:

To begin the execution flow of flor, it is important to start the process using the ‘flor’ gem. After starting, it's time to launch. During launch execution, it is important to mention the tasker to perform, according to the flow of execution.

 

Mentioned below are a few Basic Control flow patterns that can be used. Let's explore how to execute the taskers in various patterns.

 

a) Sequence:

Executes the 'child' expressions(taskers) in sequence.

 

flor-gem

 

Output:

 

flor-gem-terminated

 

b) Parallel Split:

Here tasker performs concurrently. It replies to its parent node when both taskers have replied.

 

flor-gem-launch

 

Output:

 

flor-gem-terminated

 

c) Synchronization:

It is the simplest flor synchronization tool. The concurrence waits (by default) for all its children to reply.

 

flor-gem

 

Output:

 

flor-gem-terminated

 

8) Adding tasker and Implementation class:

While adding the tasker it is required to specify the class where it will be executed. The implementation class will be ruby, which is inherited from ‘BasicTasker’. It also consists of an execution message.

 

flor-gem

 

The below code highlights how the user can perform the tasks with all the implementation related to the task. The user can fetch the data from DB and execution.

 

9) Tree format for flor:

  • In the below code, task ‘a’ and task ‘b’ is the child of sequence. In flor language, indentation holds more important.

 

flor-gem

 

  • In the below example, task ‘a’ is the child of sequence and task ‘b’ is the child of task ‘a’.

 

flor-gem-launch

 




Leave a comment: