Leased Entities
  • 09 Aug 2022
  • 6 Minutes to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Leased Entities

  • Dark
    Light

Article summary

Overview

This tutorial demonstrates how to create and use Leased Entities. A Leased Entity is a simple Database Structure (User Defined) that can be used instead of a regular Database Structure (User Defined) in cases where large data sets need to be processed. Entity Leasing technology allows multiple Threads and Servers to process Data Items in parallel. This optimizes and speeds up the process. By Leasing Entities, memory is protected from overflowing compared to the process of Fetching all Entities and trying to process them all at once.

Default Text Length
The default setting for all text stored in the database is 255 characters. However, this can be modified using the Changing Default Text Length Settings article.

Example

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

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

    2019-06-27_1029.png

  2. In the Add Leased Data Structure dialog, define the Structure similarly to one would define a Database Structure. 
  3. Name the Structure. 
  4. Using the Add button, create Fields for the Structure. 
  5. To create Actions for this structure, check the Enable Actions check box.
  6. Select OK to save and continue.
    2019-06-27_1039.png
  7. Make a Flow that will create Entities of the Lease Data Structure type. In the Designer Folder, select CREATE FLOW on the Folder Actions Panel
  8. In the resulting window, name the Flow and click CREATE to proceed to the Flow Designer.

    2019-06-27_1338.png

  9. To create Entities in this Flow, use a CSV file with 1000 records of randomly generated data.

    2019-06-27_1137.png

  10. In the Flow Designer, add a Create Data step from the Favorite Steps category.
    2019-06-27_1140.png
  11. In the Edit stepselect the Create Data dialog, click Show Editor under Data Definition, name the data, and define its type as FileData
  12. Select PICK to save and continue.
  13. Click CLOSE to continue building the Flow.

    2019-06-27_1144.png

  14. Select the Create Data step on the workspace to define a Constant CSV File for the File Input.
    2019-06-27_1145.png
  15. After the Create Data step in the Flow, add a For Each Excel or CSV Row step from the All Steps [Catalog] > Data > List > Excel and CSV category.
    2019-06-27_1236.png
  16. Select the For Each Excel or CSV Row step on the workspace to set it up. 
  17. In the Input Data section, set Input File Type - CSV, Ignore First Row – true, CSV Delimiter – Comma. 
  18. In the Inputs section for File Input, choose Select Value of the file defined in the Create Data step. 
  19. Connect the Done outcome from the For Each Excel or CSV Row step to the End step in the Flow.
    2019-06-27_1241.png
  20. On the Next Row outcome from the For Each Excel or CSV Row step, add Create NameLeasedStructure (generated by the System for the Leased Database Structure) from the Integrations > My Integrations > User Defined Types > Database Structures [Leased] > NameLeasedStructure category.
    2019-06-27_1248.png
  21. Select Show Mapping Editor for the Create NameLeasedStructure step.
  22. In the Mapping Editor, choose Build Data for Item to Create.
    2019-06-27_1319.png
  23. Map the data of Fields.Text Value from the CSV Row to the properties of the NameLeasedStructure object. 
  24. Save and close the Mapping Editor.
    2019-06-27_1325.png
  25. Back in the Flow Designer, connect the Done outcome from the Create NameLeasedStructure step back to the For Each Excel or CSV Row step. 
  26. This completes the Flow. Save and close the Flow Designer.

Leased Entities in the Workflow Process

This example will demonstrate how to use Leased Entities in the Workflow process.

  1. In the Designer Folder, create another Flow. 
  2. Name the Flow and click CREATE to proceed to the Flow Designer.

    hellooooo.png

  3. In the Flow Designer, add a Go Async [Queue] step from the All Steps [Catalog] > Flow Management category. 
  4. Use this step to run the Flow Asynchronously on the Work Queue.

  5. Add a Lease Entity step from the Integrations > All Integrations > Entity Framework > Leasing category.

  6. Select the Lease Entity step in the workspace to configure it. 
  7. In the Entity Fetch Definition section, select the Leased Entity Structure as the Type Name.

    2019-06-27_1351.png

  8. Pick a Field for the Fetch Criteria and a condition. The Field being Fetched is not recommended to be an Entity ID.
    Lease Entities

    Lease Entities look up the chosen Type, get the first Entity and Lease it for the configured amount of time. Then, the Entity is either released or deleted. 

    2019-06-27_1402.png
  9. On the Leased Entity outcome from the Lease Entity step, add the [Start Linked Flow Async] step from the Flows, Rules, Forms, and Reports > Flows category.
  10. Process the Leased Entity in this Flow. Use the Start Linked Flow Async step to be able to Lease several Entities at the same time on different threads.
    2019-06-27_1402.png
  11. Select Create or Pick Flow on the [Start Linked Flow Async] step.
    2019-06-27_1418.png
  12. Name the Flow and select CREATE to proceed to the Flow Designer on the resulting window.
    2019-07-30_1616.png
  13. In the Flow Designer, select the Start step in the workspace. 
  14. Then Add the New Flow Input of the Leased Entity Structure Type.
    2019-06-27_1428.png

  15. Add String Flow Input data to be the LeaseID for the Leased Entity.
  16. Add a Save Entities step from Integration > All Integrations > Entity Framework category after the Start step in the Flow.
    2019-06-27_1435.png
  17. Select the Save Entities step and pick the Leased Entity Structure as a Type for the Entity Save Definition.
    2019-06-27_1523.png
  18. Select Show Mapping Editor for the Save Entities step. In the Mapping Editor, Build Data for the Entity to Save.
  19. Map all Fields from the Entity Flow Input to the Entity to Save except ID
  20. For the ID Field, use the Merge Plain Text Mapping Type and click Show Editor.
    2019-06-27_1442.png
  21. In the Merge Text Editor, use the Entity ID Field along with Flow Data Start Time to modify the Entity ID
  22. Click OK to save and continue. Then save and close the Mapping Editor.
  23. Back in the Flow Designer, add a Release Lease step from the Integration > All Integrations > Entity Framework > Leasing category.
    2019-06-27_1450.png
  24. Select Show Mapping Editor for the Release Lease step.
    2019-06-27_1454.png
  25. In the Mapping Editor, map Entity Flow Input Data to the Entity Field, LeasedID Flow Input Data to the Leased ID Field, and set up a Constant time for the How Long Field. 
  26. Save and close the Mapping Editor.
    2019-06-27_1500.png
  27. After the Release Lease step in the Flow, add a Log (Fast) step from the All Steps [Catalog] > Flow Management category.
    2019-06-27_1503.png
  28. Select Show Mapping Editor for the Log (Fast) step.
  29. In the Mapping Editor, select Constant Warn level for Log and Ignore all Logs except log01
  30. For log01, pick the Merge Plain Text Mapping Type and click Show Editor.
    2019-06-27_1507.png
  31. Use the Entity's Fields in the Merge Text Editor to write to the Log. 
  32. When finished, click OK to save and close Merge Text Editor. Save and close the Mapping Editor.
  33. Back in the Flow Designer, connect the Done outcome from the Log (Fast) step to the End step. 
  34. This completes the Linked Flow. Save and close the Flow Designer.
    2019-06-27_1532.png
  35. In the Main Flow on the No Entity to Lease outcome from the Lease Entity step, add a Log (Fast) step from the All Steps [Catalog] > Flow Management category.
    2019-06-27_1549.png
  36. Connect the Done outcome from the Log (Fast) step to the End Step in the Flow and the Show Mapping Editor for the Log (Fast) Step.
  37. In the Mapping Editor, pick Constant Warn level for Log; ignore all Logs except log01. 
  38. For log01, define a Constant String saying, ' There are No Entities to Lease.' 
  39. Save and close the Mapping Editor.

    2019-06-27_1558.png

  40. This completes the Main Flow. Save and close the Flow Designer.
  41. In the Designer Folder, Run the Create Leased Entities FlowThen, Run the Lease Entity Flow.
  42. The Entities are being Leased and processed on a Workflow queue. Check this in the System > Administration > Systems > Jobs and Events on the Workflow Queues Page.
    Screen Shot 2019-07-31 at 10.59.14 AM.png

Was this article helpful?