Oracle APEX 23.1 introduced some process improvements, including a new process type: Execution Chain, which allows you to create a sequence of processes executed in the foreground or background. In this blog, I will demonstrate an introductory look into the Execution Chain process type.
In an APEX application page, I have created a simple process to replicate a potentially longer-running process using sys.dbms_session.sleep. This process doesn’t use the new Execution Chain but is just a normal Execute Code process type to execute the stated PL/SQL code. The sleep time is user-defined, and the process is triggered by a button click.
With this more traditional process type, on the execution of the process, it runs in the foreground, and any post-processing actions e.g. branches, are delayed until the process is complete. Typically, a spinner will be displayed while the process is in progress.
Execution Chain type processes are created in a similar way as other process types e.g., on Page Render (Pre-Rendering or Post-Rendering), on Page Submit (After Submit or Processing) or on demand as an AJAX Callback.
Once created, you can associate other child processes, such as PL/SQL processes, with it. There is an ‘Add Child Process’ option in the right-click context menu for Execution Chain types.
In defining your Execution Chain, initially, there is a key attribute to consider:
If Run in Background is switched on, then several other attributes become available:
Once the Execution Chain has been created, you can add child processes to it. These are created in the normal way but then associated with the Execution Chain using the ‘Execution Chain’ attribute.
To support Execution Chains, Oracle has provided a view (APEX_APPL_PAGE_BG_PROC_STATUS) and API (APEX_BACKGROUND_PROCESS).
The APEX_APPL_PAGE_BG_PROC_STATUS view provides details of the submitted Execution Chain, including Status, Status Message, Progress made so far (SOFAR), and the Total Work (TOTALWORK) to be carried out.
The APEX_BACKGROUND_PROCESS API provides the following functions/procedure:
I created a simple Execution Chain to run in the background to return the execution ID to a Global Page Item P0_EXECUTION_ID. I limited the user to three executions.
I created a couple of child processes, both performing similar functionality, an example of which can be seen below. The processes, like my earlier normal foreground process, use the sleep time set by user input. In addition, I make use of the API to:
In addition, for my application, I have created:
As with my traditional foreground process, in the application, the user triggers the new Execution process by specifying a sleep time and clicking a button to submit the page.
This time, however, because the process is running in the background, the branch to another page executes immediately, not waiting for the process to complete. The target page is the report page displaying the progress of my process.
The report refreshes intermittently, showing the appropriate Status Message for that stage in the chain and progress against the total workload (see three screenshots below).
Then, as the user navigates around the application, on the first application page load after the process has completed successfully, a notification is displayed informing them of such.
The addition of the Execution Chain process to the APEX armour certainly simplifies navigating around the application while a background process is executed. With the provided supporting view and API, it becomes easier to track the progress of those processes and report on progress compared with scheduled jobs, as would have been required before APEX 23.1.
Remember to follow us on LinkedIn. We publish insight blogs on the latest technology developments every week.
Subscribe to Oracle APEX Insights if you want to stay tuned for more APEX updates.