Leased Entities

Last Updated: 03/27/2018 Introduced in Version: 3.5

This tutorial demonstrates how to create and use Leased Entities in Decisions. Leased Entity is a simple Database Structure (User Defined) that can be used instead of regular Database Structure (User Defined) in cases where we need to process large sets of data. Using Entity Leasing technology allows to utilize multiple Threads and Servers to process Data Items in parallel. This optimizes and speeds up the process. Moreover, by Leasing Entities we protect memory from overflowing compare to the process where we would Fetch all Entities and try to process them at one time.

Example:

In this example we are going to create User Defined Database Structure [Leased], create a Set of Entities of this type, and then use and explain Entity Leasing technology.

We begin in Designer Folder by clicking Datatypes/Database > User Defined Types > Database Structure [Leased] on the Folder Actions Panel.

In the Add Leased Data Structure window we define our Structure in the similar manner as we would define Database Structure. First, we Name our Structure. Then, using Add button we create Fields for the Structure. Finally, if we are going to need to create Actions for this structure we check Enable Actions check-box. Click Ok to save and continue.

Next, we are going to create a Flow that will be creating Entities of our Lease Data Structure type. In the Designer Folder we click Create Flow on the Folder Actions Panel.  In the resulting window we Name the Flow and click Create to proceed to the Flow Designer.

 

To create Entities in this Flow we are going to use a csv file with 1000 records of random generated data.

sampleDataForEntities

First, in the Flow Designer we add Create Data step from Favorite Steps category.

 

Then, in the Edit Step: Create Data dialog we click Show Editor under Data Definition, name our Data, and define its type FileData. Click PICK to save and continue.

Next, we click CLOSE to continue building our Flow.

We select Create Data step on the works-pace to define a Constant csv File for the file Input.

Next to the Create Data step in our Flow we add For Each Excel or CSV Row step from All Steps [Catalog] > Data > List > Excel and CSV category.

Then, we select For Each Excel or CSV Row step on the work-space to set it up. In the Input Data section we set Input File TypeCSV, Ignore First Rowtrue, CSV DelimiterComma. In the Inputs section for File Input we Select Value of the file that we defined in Create Data step. Connect Done outcome from For Each Excel or CSV Row step to the End Step in our Flow.

 

On the Next Row outcome from the For Each Excel or CSV Row step we add Create NameLeasedStructure (generated by the System for our Leased Database Structure) from Integrations > My Integrations > User Defined Types > Database Structures [Leased] > NameLeasedStructure category.

Then, we Show Mapping Editor for Create NameLeasedStructure step.

In the Mapping Editor we Build Data for Item to Create.

Next, we map data of Fields.Text Value from our CSV Row to the properties of our NameLeasedStructure object. When finished, save and close Mapping Editor.

Back in the Flow Designer we connect Done outcome from Create NameLeasedStructure step back to For Each Excel or CSV Row step. This completes our Flow. We can save and close Flow Designer.

Next, we are going to demonstrate how to use Leased Entities in Workflow process.

In the Designer Folder create another Flow.  Then, we Name the Flow and click CREATE to proceed to the Flow Designer.

In the Flow Designer we add Go Async [Queue] step from All Steps [Catalog] > Flow Management category. We use this step to run our Flow Asynchronously on the Work Queue.

Then, we add Lease Entity Step from Integrations > All Integrations > Entity Framework > Leasing category.

Next, we select Lease Entity Step on the work-space to configure it. Lease Entity Step works similar to Fetch Entities Step except several differences. First, in Entity Fetch Definition section we select our Leased Entity Structure as Type Name.

Then, we pick a Field to Fetch On and Condition. Note, the field we Fetch on is not recommended to be Entity ID. The way Lease Entity works is following… It looks up for the chosen Type, gets the first Entity and Leases it for the configured in Lease Setup configuration section amount of time. Then, we can either Release Entity or Delete Leased Entity.

Next, on Leased Entity outcome from Lease Entity Step we add [Start Linked Flow Async] step from Flows, Rules, Forms and Reports > Flows category. In this Flow we are going to process our Leased Entity. In this example we use Start Linked Flow Async to be able to Lease several Entities at the same time on different threads.

Then, on the [Start Linked Flow Async] Step we select Pick or Create Flow.

On the resulting window we Name the Flow and click Create to proceed to the Flow Designer.

In the Flow Designer we select Start Step on the works-pace. Then, we Add New Flow Input of our Leased Entity Structure Type.

Also, we add String Flow Input data to be LeaseID for our Leased Entity.

 

Then, we add Save Entities step from Integration > All Integrations > Entity Framework category after Start Step in our Flow.

 

Next, we select Save Entities Step and Pick our Leased Entity Structure as a Type for Entity Save Definition.

Then, we click Show Mapping Editor for Save Entities Step. In the Mapping Editor we Build Data for Entity to Save.

Then, we map all fields from Entity Flow Input to Entity to Save except ID. For ID field we use Text Merge.Plain Mapping Type and click Show Editor.

In the Merge Text Editor we use Entity ID field along with Flow Data Start Time to modify Entity ID. Click Ok to save and continue. Then, we save and close Mapping Editor.

Back to the Flow Designer we add Release Lease Step from Integration > All Integrations > Entity Framework > Leasing category.

Then, we Show Mapping Editor for Release Lease step.

In the Mapping Editor we map Entity Flow Input Data to entity field, LeasedID Flow Input Data to leasedId field and set up Constant time forHowLong field. Then, we can save and close Mapping Editor.

After Release Lease step in our Flow we add Log (Fast) step from All Steps [Catalog] > Flow Management category.

Then, we Show Mapping Editor for Log (Fast) step.

In the Mapping Editor we select Constant Warn level for Log, Ignore all Logs except log01. For log01 we pick Text Merge.Plain Mapping type and click Show Editor.

In the Merge Text Editor we use Entity’s fields to write to the Log. When finished we can click Ok to save and close Merge Text Editor. Then, we save and close Mapping Editor.

Back in the Flow Designer we connect Done outcome from Log (Fast) step to the End Step. This completes our Linked Flow. We can save and close Flow Designer.

Back in the Main Flow on the No Entity to Lease outcome from Lease Entity Step we add Log (Fast) Step from All Steps [Catalog] > Flow Management category.

Then, we connect Done outcome from Log (Fast) step to the End Step in our Flow and Show Mapping Editor for Log (Fast) Step.

In the Mapping Editor we pick Constant Warn Log level, Ignore all Logs except log01, and for log01 define Constant String saying that ‘There are No Entities to Lease’. Then, save and close Mapping Editor.

This completes our Main Flow. We can save and close Flow Designer.

Back in the Designer Folder we Run Create Leased Entities Flow…

Then, we Run Lease Entity Flow

Our Entities are being Leased and processed on a Workflow queue. We can check this in System > Administration > System Tools > Flow Management Folder on Workflow Queues Page.

flowInQueue

 

 

 

Additional Resources