Question

Hey guys, I'm wondering how you create a job scheduler in Oracle APEX?

I'm making a system which manages calls, each call has a severity level. After an hour, the severity level should be escalated. I have searched for hours, and I guess that I need to make a procedure which defines a job scheduler and then runs the update?

If you guys could throw some suggestions my way, I'd appreciate it!

Cheers Rich

Was it helpful?

Solution

To my mind, the simplest possible solution that could possibly work would be something like

CREATE PROCEDURE escalate_cases
AS
BEGIN
  UPDATE tickets
     SET status = 'ESCALATED'
   WHERE status = 'NOT ESCALATED'
     AND open_date < sysdate - interval '1' hour;
END escalate_cases;

DECLARE
  l_jobno PLS_INTEGER;
BEGIN
  dbms_job.submit( 
    l_jobno,
    'BEGIN escalate_cases(); END;',
    sysdate + interval '1' minute,
    'sysdate + interval ''1'' minute'
  );
  dbms_output.put_line( 'Job ' || l_jobno || ' submitted.' );
  commit;
END;

The procedure escalates all the tickets that meet your criteria and the anonymous block creates a job that runs the procedure every minute. A single job that runs every minute (or every few minutes depending on your tolerance for long you can wait to escalate a ticket) is going to be easier to manage than a separate job for each ticket that runs exactly 1 hour after it has been submitted.

Now, if you want to get a bit more sophisticated, the DBMS_SCHEDULER package offers quite a bit of functionality that the DBMS_JOB package does not. It provides some automatic logging, it provides the ability to chain jobs, to define various windows where jobs do and do not run (i.e. if a ticket is created at 5:30, you may not want to escalate it at 6:30 because it is after hours), etc. And DBMS_SCHEDULER is the direction Oracle is moving. But I still find myself using DBMS_JOB for relatively simple tasks like this.

OTHER TIPS

Check out the material here

I've used the method listed by Justin with good success. Another method that works well is to use a queue with delayed delivery. That gives you the ability to have an external paging program or something wait on the queue for escalations. I'm not that familiar with APEX so I'm not sure if that's a good idea in that context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top