Introduction

Getting started

Walkthrough Guides

CafeX Apps

Workflows

Using CafeX Collaborate App

Reporting

Managing CafeX

Integrating CafeX

Security

App Studio

App Studio Components

How-tos

How-tos

Configuring a Task Queue

Modified on Wed, 5 Mar at 7:15 AM

Overview

In applications where users process multiple documents or tasks sequentially, keeping the session active in the background helps maintain a seamless workflow. The Task Queue enables pre-loading the next document while the current one is in use, minimizing wait times. This guide provides a step-by-step overview of the setup, configuration, and event handler sequence needed to implement this functionality.


How It Works

Task Queue is designed to improve user experience and application performance by ensuring seamless task transitions. While a user is working on one document, the application pre-loads the next document in the background. Once the current document is completed, the pre-loaded document becomes active, and the next one starts loading. A keep-alive timer runs in the background to prevent session termination. 


The process follows these key steps:

  1. User Works on Current (Foreground) Task: The user interacts with an active task while the system tracks session activity.

  2. Preloading the Next (Background) Task: While the user is engaged, the next document/task is fetched from an external API and stored in a background queue.

  3. Keep-Alive Timer Activation: A timer continuously refreshes session activity and preloaded task data to prevent expiration.

  4. Task Completion Event: When the user completes a task, the preloaded document/task is seamlessly transitioned into the active state.

  5. Updating Task QueueThe queue updates dynamically, fetching and preloading the next document/task in the sequence.

  6. Maintaining Session Activity: The system periodically refreshes session-related data sets, preventing session expiration and ensuring uninterrupted workflow.


Configuration Steps

The session activity management process consists of:

  1. Adding external data sources.

  2. Creating necessary data sets.

  3. Setting up UI components.

  4. Creating timers.

  5. Configuring event handlers.

  6. Managing timers.


Step 1: Add external data sources

In this step, we'll add two external data sources that will serve as the foundation for retrieving tasks in our application. These sources will allow us to create Data sets of the External API type in Step 2.

  • Foreground Task Source represents tasks that are actively being processed.
  • Background Task Source represents tasks that are queued and waiting to be processed next.
  1. Open the External data sources page () and click Add new data source.
  2. In our example, we'll add two external data sources with the following configurations:
    Foreground Task Source 
    SettingValue
    NameForeground Task Source
    Request
    {
      "url": "https://api-generator.retool.com/H4kq29/data",
      "method": "GET",
      "urlParameters": [
        {
          "name": "_page"
        },
        {
          "name": "_limit"
        }
      ]
    }
            
    ResponseFor Response type Success, click Extract Schema > Send Request > Accept.
  3. Click Add.
  4. Repeat the same configuration for the second external data source, named Background Task Source.


Step 2: Create Data sets for the App

In this step, we'll define data sets that will be evaluated and updated as users transition between documents.

To add a Data set:

  1. Under Explorer and Components > Explorer, click App.
  2. Under Appearance and Configuration > Configuration, locate the Data sets section. Click Add data set.
  3. Enter the suggested values for each Data set:
1.  Active Record Data set

This data set stores the currently active task that the user is working on.

SettingValue
NameActive Record
TypeVariable
Evaluate automaticallyEnabled


2. Active Record Object Data set

This data set transforms the Active Record data set into a structured JavaScript object for easier data manipulation.

SettingValue
NameActive Record Object
TypeJavascript
Evaluate automaticallyEnabled
InputsData set: Active Record
Required: Enabled
OutputOutput data type: Object
Array: Enabled
Add fields: Column 1 (Text type), id (Number type)
Code
return inputs['Active Record']


3. Task Queue Object Data set

This data set generates a predefined array of task IDs in JavaScript.

SettingValue
NameTask Queue Object
TypeJavascript
Evaluate automaticallyEnabled
OutputOutput data type: Text
Array: Enabled
Code
return ["1", "2", "3", "4", "5", "6"];


4. Task Queue Data set

This data set stores a list of all task IDs that are currently in the queue.

SettingValue
NameTask Queue
TypeVariable
Expression{{{Task Queue Object}}}
Evaluate automaticallyEnabled


5. Foreground Task ID Data set

This data set stores the ID of the current active task, which is the first item in the task queue. It helps track the task that is currently being processed.

SettingValue
NameForeground Task ID
TypeVariable
Expression{{Task Queue.0}}
Evaluate automaticallyEnabled


6. Background Task ID Data set

This data set holds the ID of the next task in the queue.

SettingValue
NameBackground Task ID
TypeVariable
Expression{{Task Queue.1}}
Evaluate automaticallyEnabled


7. Get Foreground Task ID Data set

This data set retrieves detailed information about the currently active task from the Foreground Task Source external source. It takes the task ID as an input and returns the corresponding task data.

SettingValue
NameGet Foreground Task ID
TypeExternal API
SourceForeground Task Source
InputsInput: _page, Location: Foreground Task ID, Requirement: Not null
Input: _limit, Requirement: Any value


8. Get Background Task ID Data Set

This data set retrieves information about the next task in the queue from the Background Task Source external source. It uses the next background (queued) task ID as input to retrieve the relevant data.

SettingValue
NameGet Background Task ID
TypeExternal API
SourceBackground Task Source
InputsInput: _page, Location: Background Task ID, Requirement: Not null
Input: _limit, Requirement: Any value


9. Task Queue Limit Data Set

This data set defines the default limit (20) for fetching records to ensure consistency in pagination.

SettingValue
NameTask Queue Limit
TypeVariable
Expression20
Evaluate automaticallyEnabled


10. Updated Task Queue Data Set

This data set generates a new version of the task queue by removing the first task from the Task Queue data set. It helps update the queue dynamically as tasks are processed.

SettingValue
NameUpdated Task Queue
TypeJavascript
Evaluate automaticallyDisabled
InputsData Set: Task Queue
Required: Enabled
OutputOutput data type: Text
Array: Disabled
Code
const arrayOfTasks = inputs['Task Queue'];
return arrayOfTasks.slice(1);


11. Keep-Alive Timer Active Data Set

This data set serves as a switch to indicate whether a timer should be active.

SettingValue
NameKeep-Alive Timer Active
TypeVariable
Expressionfalse
Evaluate automaticallyEnabled


12. Show Completion Timer Data Set

This data set controls the visibility of the job completion timer.

SettingValue
NameShow Completion Timer
TypeVariable
Expressionfalse
Evaluate automaticallyEnabled


Step 3: Add Components

Add the following UI components to the App:


ComponentConfiguration
Button 1 / Current TaskName: Current Task
Text: Current Task
Button 2 / Next TaskName: Next Task
Text: Next Task
Text 1
(Displays active record information)
Name: Current Task
Text: {{{Foreground Task ID}}}
Text 2
(Displays next record information)
Name: Next Task
Text: {{{Background Task ID}}}
Table
(Displays list of records)
Read only: enabled
Configuration > Data set: Select the Active Record Object data set
Side panel ComponentVisibility: {{{Show Completion Timer}}}
Added inside the Side panel Component: Container Component
Added inside the Container Component: Text Component
Text: Task complete


Step 4: Configure Timers

In this step, we'll configure two timers, required to  keep task data up to date and manage the display of job completion notifications.

  • Session Refresh Timer ensures that the queued task data remains updated by periodically refreshing the relevant data set while Keep-Alive Timer Active is active.
  • Job Complete Timer manages the visibility of the job completion notification, automatically hiding it after a set duration.

To configure a timer:

  1. Go to the Timer management page () and click the plus icon to create a new Interval timer.
  2. Provide the following details for the first timer:
    Session Refresh Timer
    SettingValue
    NameSession Refresh Timer
    Delay (seconds)10
    Condition{{{Get Background Task ID}}} && {{{Keep-Alive Timer Active}}}
    Event HandlersClick the plus icon and add the event handler:
    • Handler name: Refresh endpoint
    • Event type: Delay time elapsed
    • Action: Evaluate a data set
    • Data set to evaluate: Get Background Task ID

  3. Click the plus icon to add another Interval timer with the following configuration:
    Job Completion Timer
    SettingValue
    NameJob Completion Timer
    Delay (seconds)10
    Condition{{{Show Completion Timer}}}
    Event HandlersClick the plus icon and add the event handler:
    • Handler name: Stop timer
    • Event type: Delay time elapsed
    • Action: Set a variable
    • Variable to set: Show Completion Timer
    • Value to set: false


Step 5: Configure Event Handlers

Active Task button's configuration consists of the following event handlers, which should be configured in the same order as listed below:


1. Load Foreground Task Data

This event handler retrieves data for the active foreground task by evaluating the Get Active Task data set. It ensures that the latest task details are fetched when triggered.

SettingValue
Handler NameLoad Foreground Task Data
Event TypeClick
ActionEvaluate a data set
Data SetGet Foreground Task ID
Wait for ResponseEnabled
Continue on ErrorDisabled


2. Load Background Task Data

This event handler retrieves data for the next queued background task by evaluating the Get Background Task ID data set. It ensures that the queued task information is updated when needed.

SettingValue
Handler NameLoad Background Task Data
Event TypeClick
ActionEvaluate a data set
Data SetGet Background Task ID
Wait for ResponseEnabled
Continue on ErrorDisabled


3. Start Session Refresh Timer

This event handler activates the Session Refresh Timer by setting the Keep-Alive Timer Active variable to true. This allows periodic updates of the queued task while processing is active.

SettingValue
Handler NameStart Session Refresh Timer
Event TypeClick
ActionSet a variable
Variable to SetKeep-Alive Timer Active
Value to Settrue


4. Set Active Record

This event handler updates the Active Record variable with the most recent data retrieved from the Get Active Task data set. It ensures that the App reflects the latest foreground task details.

SettingValue
Handler NameSet Active Record
Event TypeClick
ActionSet a variable
Variable to SetActive Record
Value to Set{{{Get Foreground Task ID}}}



Next Task button's configuration consists of the following event handlers, which should be configured in the same order as listed below:


1. Stop Notification Timer

This event handler disables the Show Completion Timer by setting its value to false. It ensures that the job completion message is hidden when triggered.

SettingValue
Handler NameStop Notification Timer
Event TypeClick
ActionSet a variable
Variable to SetShow Completion Timer
Value to Setfalse


2. Start Notification Timer

This event handler enables the Show Completion Timer by setting its value to true. It ensures that the job completion message is displayed when triggered.

SettingValue
Handler NameStart Notification Timer
Event TypeClick
ActionSet a variable
Variable to SetShow Completion Timer
Value to Settrue


3. Set Active Record

This event handler updates the Active Record variable with the most recent data retrieved from the Get Active Task data set. It ensures that the foreground task is set as the active record.

SettingValue
Handler NameSet Active Record
Event TypeClick
ActionSet a variable
Variable to SetActive Record
Value to Set{{{Get Background Task ID}}}


4. Update Active Record 

This event handler evaluates the Active Record Object data set to ensure that the active record data is properly processed and updated.

SettingValue
Handler NameSet Active Record JS
Event TypeClick
ActionEvaluate a data set
Data Set to EvaluateActive Record Object
Wait for ResponseEnabled
Continue on ErrorDisabled


5. Update Task Queue

This event handler processes the Updated Task Queue data set, which removes the first task from the queue and keeps the task queue updated

SettingValue
Handler NameUpdate Task Queue
Event TypeClick
ActionEvaluate a data set
Data Set to EvaluateUpdated Task Queue
Wait for ResponseEnabled
Continue on ErrorDisabled


6. Update Background Task ID

This event handler updates the Next Task variable with the new first task from Updated Task Queue.

SettingValue
Handler NameUpdate Background Task ID
Event TypeClick
ActionSet a variable
Variable to SetBackground Task ID
Value to Set{{{Updated Task Queue.1}}}


7. Stop Session Refresh Timer

This event handler stops the Session Refresh Timer by setting Keep-Alive Timer Active to false.

SettingValue
Handler NameStop Session Refresh Timer
Event TypeClick
ActionSet a variable
Variable to SetKeep-Alive Timer Active
Value to Setfalse


8. Refresh Background Task Data

This event handler evaluates the Get Background Task ID data set to fetch the most recent background task data and keeps the App updated with the latest queued task information.

SettingValue
Handler NameRefresh Background Task Data
Event TypeClick
ActionEvaluate a data set
Data Set to EvaluateGet Background Task ID
Wait for ResponseEnabled
Continue on ErrorDisabled


9. Start Session Refresh Timer

This event handler restarts the Session Refresh Timer by setting Keep-Alive Timer Active to true.

SettingValue
Handler NameStart Session Refresh Timer
Event TypeClick
ActionSet a variable
Variable to SetKeep-Alive Timer Active
Value to Settrue


10. Update Task Queue

This event handler updates the Task Queue variable with the new task queue from Updated Task Queue and keeps the queue accurate after a task is removed.

SettingValue
Handler NameUpdate Task Queue
Event TypeClick
ActionSet a variable
Variable to SetUpdate Task Queue
Value to Set{{{Updated Task Queue}}}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article