Tuesday, 27 April 2010

the problem with jobs

Often a job only breaks because it wasn't able to access another server temporarily for example, in the meantime the server comes back online but the job is still broken.

Unless a user tells you you might never know that then job has broken, but there is something you can do about it. You can create a "fixer job", this is a job that looks at all the other jobs at a set interval and if it finds one that is broke then it fixes it, you could even get it to log the fix or email you when one of the jobs break.

This is the procedure I use in PL/SQL to fix it:

CREATE OR REPLACE PROCEDURE job_fixer
AS

CURSOR broken_jobs_cur
IS
SELECT job
FROM user_jobs
WHERE broken = 'Y';

BEGIN
FOR job_rec IN broken_jobs_cur
LOOP
DBMS_JOB.BROKEN(job_rec.job,FALSE);
END LOOP;
END job_fixer;

1 comment:

Dan said...

I originaly got this code from here: http://www.dba-oracle.com/t_fixing_broken_jobs.htm