1

Within Oracle APEX v4.2, I have an application by where a user presses a button which then goes off and submits a scheduled background job, allowing the user to continue working within the application. The job is kicked off using Oracle's DBMS_SCHEDULER.

My question is and want to keep it within the Oracle APEX space - assuming there is a table that stores when the job was initiated as well as when it eventually completes, how can I interact with this table, check whether the job has completed (i.e. somehow poll the table and stop when the "COMPLETE" status is found) and then, provide an 5 second alert that slides in and then slides out, notifying the user that the job has completed.

Can I use JavaScript (callback) via Dynamic Actions?

halfer
  • 19,824
  • 17
  • 99
  • 186
tonyf
  • 34,479
  • 49
  • 157
  • 246

1 Answers1

0

If you don't want to go down the plugin route, you can use the following code in an Application Process, called ProgressCheck in this instance:

DECLARE

CURSOR c_time_elapsed 
IS
SELECT  SUBSTR(elapsed_time,6,2)||'hrs '
       ||SUBSTR(elapsed_time,9,2)||'mins '
       ||SUBSTR(elapsed_time,12,2)||'secs'    ELAPSED_TIME
FROM    user_scheduler_running_jobs
WHERE   job_name    =   'XX_YOUR_JOB_NAME'
UNION ALL
SELECT '00:00'
FROM   DUAL
WHERE  NOT EXISTS  (SELECT  SUBSTR(elapsed_time,9)  ELAPSED_TIME
                    FROM    user_scheduler_running_jobs
                    WHERE   job_name    =   'XX_YOUR_JOB_NAME');

BEGIN

FOR r_time IN c_time_elapsed LOOP

    htp.p('<p>Time elapsed: '||r_time.ELAPSED_TIME);

END LOOP;
htp.p('');

END;

In the Page header, include the following JavaScript:

<script type="text/javascript">
<!--
var myInterval;

function f_ProgressCheck(){
    var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=ProgressCheck',$v('pFlowStepId'));
    gReturn = get.get();
    get = null;
    gReturn = (!gReturn)?'null':gReturn;
    $s('P1_PROGRESS_RESULT',gReturn);
}

function f_myInterval(){
         myInterval = setInterval ( "f_ProgressCheck()", 5000 );
}

//-->
</script>

This will call the Application Process every five seconds once your page has loaded and will put the results of the check into P1_PROGRESS_RESULT.

You can amend the Application Process to suit your requirements, perhaps returning something else or additionally checking for completion, like in the following code:

DECLARE

CURSOR c_job_count 
IS
SELECT  COUNT(*) TOTAL
FROM    user_scheduler_job_log
WHERE   job_name = 'XX_YOUR_JOB_NAME'
AND     log_date >= (SYSDATE - 1/1440); 

BEGIN

FOR r_job_count IN c_job_count LOOP
    IF r_job_count.total = 1 THEN
      htp.p('<p>Your data is ready to view.');
      htp.p('<p>Click Go to view the report.');
      htp.p('<input type="button" onclick="javascript:this.disabled=true;this.value=''Please wait...'';doSubmit(''REPORT'');" value="Go" class="RelevantAPEXClass" />');
    ELSE
      htp.p('<p>');
    END IF;
END LOOP;

END;

You could also combine the PLSQL to deliver everything in one process.

You could also call the PLSQL (preferably) using a Dynamic Action.

Pete Mahon
  • 105
  • 1
  • 12