18.6.1 Reporting Background Process to Users

Report background process status and progress from PL/SQL as each step completes.

To report progress and current status of a background process, use SET_PROGRESS and SET_STATUS procedures in the APEX_BACKGROUND_PROCESS package. As shown below, your code sets the total amount of work as a number in some appropriate units. It also sets the work completed so far using another number in the same units.

The package code related to the Employee Excellence award review processing establishes a total of 9 units of TOTALWORK, and increments the SOFAR value as it completes each of the 9 different steps. The GATHER_PERFORMANCE_INFORMATION below accomplishes three of the nine total steps. At each step the code updates the current background process status and progress.

Tip:

The APEX_BACKGROUND_PROCESS procedures implicitly work on the currently executing background process id. If necessary, call the GET_CURRENT_EXECUTION function in this package to access a T_EXECUTION record with key information about the current executing background process including the execution ID, STATE, LAST_STATUS_MESSAGE, SOFAR, and TOTALWORK.

-- In package eba_demo_woodshr_reward
c_steps constant pls_integer := 9;

procedure gather_performance_information(
    p_empno in number)
is
begin
    apex_background_process.set_progress(p_totalwork => c_steps, p_sofar => 0);
    apex_background_process.set_status('Gathering Project Management Details');
    --     ⋮
    apex_background_process.set_progress(p_totalwork => c_steps, p_sofar=> 1);
    apex_background_process.set_status('Gathering 360 Feedback Information');              
    --     ⋮
    apex_background_process.set_progress(p_totalwork => c_steps, p_sofar => 2);
    apex_background_process.set_status('Gathering Attendance Records');              
    --     ⋮
    apex_background_process.set_progress(p_totalwork => c_steps, p_sofar => 3);
    apex_background_process.set_status('Gathering Completed');              
end gather_performance_information;