开发者

dbms_job / Oracle job scheduler

开发者 https://www.devze.com 2023-01-29 13:56 出处:网络
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

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!开发者_StackOverflow中文版

Cheers Rich


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消