Page 1 of 1

To Run a Job thro Routines

Posted: Wed Aug 04, 2004 5:20 am
by suma
I just want to create a simple routine that should run my Job,If the Job failed the error should be logged! Can any one help me out in solving my Problem. I tried writing routines through some examples.But it throws errors
Here is the sample routine,,, Can anyone correct me where i am wrong!!

Hjob1 = DSAttachJob("test1",DSJ.ERRFATAL)
Dummy = DSSetParam(Hjob1,"Param1","Value1")
Dummy = DSRunJob(Hjob1,DSJ.RUNNORMAL)
J1stat = DSGetJobInfo(Hjob1, DSJ.JOBSTATUS)
If J1stat = DSJS.RUNFAILED
Then Call DSLogFatal("Job DailyJob1 failed","JobControl")
End

Posted: Wed Aug 04, 2004 5:45 am
by mleroux
Why write something when it can be written for you?

In designer, go to Job Properties, Job Control tab, drop down the box and select the job you want to generate code for, and click Add Job.

You can of course use the generated code as a template and modify it to your needs.

Posted: Wed Aug 04, 2004 6:39 am
by chulett
Might help to know what errors you are seeing. Also would help to wait for the job to finish before you check its status. :wink:

Posted: Wed Aug 04, 2004 9:40 pm
by ray.wurlod
Error checking!!!

You didn't check whether the job was attached successfully, and you didn't check whether DSSetParam succeeded. You (like way too many others) blithely assumed that all would be well, and proceeded to issue a run request. And, as Craig pointed out, you didn't wait for the job to complete before checking its status; when you checked its status was either "starting" or "running".

How do you know the job failed? Do you know that DSJS.RUNFAILED actually means? Is it the same? Are you aware that there are other possibilities (such as DSJS.CRASHED) that your code does not handle?

I have a number of areas of concern with the automatically generated code. which could be improved greatly. It's better than it used to be, but there's a lot more that could be done. Code generated by compiling a Job Sequence is better, in that it retains control (does not abort) but it, too, could be improved.