Batch is running !

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Simba
Participant
Posts: 22
Joined: Wed Dec 03, 2003 6:12 pm

Batch is running !

Post by Simba »

Please Help,
I am running a server job control, which executes a routine. Status of the batch still shows "running" even the routine's task completed successfully.

CONTROLLER CODE:

*$INCLUDE DSINCLUDE DSR_UVCONST.H
*$INCLUDE DSINCLUDE DSR_COMCONST.H


Arg1 = 0
Code1 = 0
Status = 0
Code = 0
DEFFUN CompileJobRoutine(Arg1,Arg2) Calling "DSU.CompileJobRoutine"
*DEFFUN TestRoutine(Arg1,Arg2) Calling "DSU.TestRoutine"


RunHandle = DSAttachJob("KeyHashBookClose", DSJ.ERRNONE)
Status = DSGetJobInfo(RunHandle, DSJ.JOBSTATUS)
Result = DSGetJobInfo(RunHandle,DSJ.JOBSTARTTIMESTAMP)
ResultDate = SUBSTRINGS(Result,1,10)
CurrentDate = Oconv(DATE(),"D4-YMD")

If Status = DSJS.RUNOK or '99' and ResultDate LT CurrentDate Then
Code = DSPrepareJob(RunHandle)
Code = DSRunJob(RunHandle,DSJ.RUNNORMAL)
End

If Status = DSJS.RUNFAILED and ResultDate LE CurrentDate Then
Arg2 = "KeyHashBookClose"
Result = CompileJobRoutine(Ans,Arg2); * compile job
Result = OCONV(Result, "MCN")
If Result >= 1 Then
Code = DSPrepareJob(RunHandle)
Code = DSRunJob(RunHandle,DSJ.RUNNORMAL)
End
End
Goto Fini

Fini:

ROUTINE CODE:
$INCLUDE DSINCLUDE JOBCONTROL.H
$INCLUDE DSINCLUDE DSR_UVCONST.H
$INCLUDE DSINCLUDE DSR_COMCONST.H


Code = Arg1
MyJobNo = Arg2
SUBR = DSR.SUB.JOB
Dummy2 = ""


Key = DSR.SUB.JOB.COMPILE
Call @SUBR(Key, Arg2)
Call DSD.Init(MyJobNo, Dummy2)

Ignore = 0
JobNo = DSRGetJob(Arg2,Ignore)
Execute "CLEAR.FILE ":DSR.RTSTATUS.FNAME:JobNo
Execute "CLEAR.FILE ":DSR.RTLOG.FNAME:JobNo
Ans = 1

Key = DSR.SUB.JOB.RELEASE ; * unlock job, ignoring any errors
Call @SUBR(Key, Arg2)
Call DSD.Init(MyJobNo, Dummy2)

Return(Ans)
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Simba

If you try to compile the current job or a job running then it does unpredictable things. Compiling the job that is running is very difficult to fix. You need to reset status and maybe pull it up in the Designer and recompile.

I would clear files after you release the job. Also there is no wait for job routine.

Kim.
Mamu Kim
Simba
Participant
Posts: 22
Joined: Wed Dec 03, 2003 6:12 pm

Post by Simba »

kduke wrote:Simba

If you try to compile the current job or a job running then it does unpredictable things. Compiling the job that is running is very difficult to fix. You need to reset status and maybe pull it up in the Designer and recompile.

I would clear files after you release the job. Also there is no wait for job routine.

Kim.
Kim,
Thanks for you reply,. I have executed a batch, which is supposed to compile a job. Based on the return code i am running the compiled in this batch. My batch in showing "running". The job i am running from this batch has been finished. By the way, please help me to use DSWaitfor.

Thanks,
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

This statement is wrong:

Code: Select all

If Status = DSJS.RUNOK or '99' and ResultDate LT CurrentDate Then 
It should be something like:

Code: Select all

If ( Status = DSJS.RUNOK or Status = '99' ) and ResultDate LT CurrentDate Then 
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Simba
Participant
Posts: 22
Joined: Wed Dec 03, 2003 6:12 pm

Post by Simba »

kcbland wrote:This statement is wrong:

Code: Select all

If Status = DSJS.RUNOK or '99' and ResultDate LT CurrentDate Then 
It should be something like:

Code: Select all

If ( Status = DSJS.RUNOK or Status = '99' ) and ResultDate LT CurrentDate Then 
Thanks Ken,
I have modified the code, Can you tell how DSLogToController() works.
I have used this function for "silent exit". Now with the following code batch is showing "finished".

If Status = (DSJS.RUNOK or '99') and ResultDate LT CurrentDate Then
Code = DSPrepareJob(RunHandle)
Code = DSRunJob(RunHandle,DSJ.RUNNORMAL)
End

**************** batch is "running" with this code************
If Status = DSJS.RUNFAILED and ResultDate LE CurrentDate Then
Result = CompileJobRoutine(Arg1,Arg2); * compile job
Result = OCONV(Result, "MCN")
If Result >= 1 Then
*Call DSLogToController("") **Not sure to include
Code = DSRunJob(RunHandle,DSJ.RUNNORMAL)
End
End
****************************************************
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Your logic is still wrong! You have:

Code: Select all

If Status = (DSJS.RUNOK or '99')
and it should be:

Code: Select all

If (Status = DSJS.RUNOK or Status = '99')
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

DSLogToController() puts messages into the job log of the parent job that started the current job.

Example:

Batch Job A starts Batch Job B. Batch Job B does a DSLogToController() call and messages appear in the log of Batch Job A.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

San

Code: Select all

* Setup AdjustmentCode, run it, wait for it to finish, and test for success
      hJob1 = DSAttachJob("AdjustmentCode", DSJ.ERRFATAL)
      If NOT(hJob1) Then
         Call DSLogFatal("Job Attach Failed: AdjustmentCode", "JobControl")
         Abort
      End
      ErrCode = DSSetParam(hJob1, "matrixsrc_dsn", "PROD")
      ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
      ErrCode = DSWaitForJob(hJob1)
      Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
      If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
         * Fatal Error - No Return
         Call DSLogFatal("Job Failed: AdjustmentCode", "JobControl")
      End
If you build a batch job then there is a drop down list of job names. Next to it is an add job button. This is the code it generates.

Code: Select all

      ErrCode = DSWaitForJob(hJob1)
The DSWaitForJob() takes the hJob1 job handle from the return DSAttachJob() routine and waits for it to finish before the next line of code is executed. Otherwise the job continues running in the background.

This maybe important to what you are trying to do. I am still not sure why you are compiling jobs this why. Wouldn't be easier to just reset a job? If all you need is to get a job in a runable state then reset is better. Unless you have some program which changes the job then do not compile it.
Mamu Kim
Simba
Participant
Posts: 22
Joined: Wed Dec 03, 2003 6:12 pm

Post by Simba »

kduke wrote:San

Code: Select all

* Setup AdjustmentCode, run it, wait for it to finish, and test for success
      hJob1 = DSAttachJob("AdjustmentCode", DSJ.ERRFATAL)
      If NOT(hJob1) Then
         Call DSLogFatal("Job Attach Failed: AdjustmentCode", "JobControl")
         Abort
      End
      ErrCode = DSSetParam(hJob1, "matrixsrc_dsn", "PROD")
      ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
      ErrCode = DSWaitForJob(hJob1)
      Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
      If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
         * Fatal Error - No Return
         Call DSLogFatal("Job Failed: AdjustmentCode", "JobControl")
      End
If you build a batch job then there is a drop down list of job names. Next to it is an add job button. This is the code it generates.

Code: Select all

      ErrCode = DSWaitForJob(hJob1)
The DSWaitForJob() takes the hJob1 job handle from the return DSAttachJob() routine and waits for it to finish before the next line of code is executed. Otherwise the job continues running in the background.

This maybe important to what you are trying to do. I am still not sure why you are compiling jobs this why. Wouldn't be easier to just reset a job? If all you need is to get a job in a runable state then reset is better. Unless you have some program which changes the job then do not compile it.
Thank you. Our goal is to run a sequence of jobs, if any of the job gets aborted then the seq should start from the aborted job. The approch is to compile and run the jobs if they are aborted. If jobs are aborted in the production. The plan is to fix them in the development and just import to production,. The status is still abort. That is why we are trying to compile and run.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

If a job aborts then reset it do not compile it. Reset was designed to clean up an abort.

Do a search. There is a routine to reset a job. Ray or Ken posted something about it this week.

Kim.
Mamu Kim
rabs
Charter Member
Charter Member
Posts: 21
Joined: Thu May 02, 2002 5:27 pm

Post by rabs »

Simba wrote: Thank you. Our goal is to run a sequence of jobs, if any of the job gets aborted then the seq should start from the aborted job. The approch is to compile and run the jobs if they are aborted. If jobs are aborted in the production. The plan is to fix them in the development and just import to production,. The status is still abort. That is why we are trying to compile and run.
Yeah mate, like Kim says you should really reset the job. Compiling jobs to get them back to a runnable state means that those jobs are editable (as far as I am aware). However, they should really be read-only on your production instance.
like a tiger
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

1. Attach job (DSAttachJob)
2. Check that attach succeeded (DSGetJobInfo(hJob, DSJ.JOBNAME))
3. Check job status (DSGetJobInfo(hJob, DSJ.JOBSTATUS))
4. If job status indicates that job is worth attempting to reset:
(a) detach job (DSDetachJob)
(b) attach job (DSAttachJob) -- probably OK not to verify again
(c) run job in reset mode (DSRunJob(hJob, DSJ.RUNRESET))
(d) wait for this to finish (DSWaitForJob)
(e) check new exit status (DSGetJobInfo)
(f) detach job
(g) attach job
5. Check job status (see 3.)
6. If job is in a runnable state:
(a) set each parameter value
(b) verify that parameter value was correctly set
(c) run the job in normal mode (DSRunJob(hJob, DSJ.RUNNORMAL))
(d) wait for job to finish -- your code
(e) interrogate job for any required information
7. Detach job.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ariear
Participant
Posts: 237
Joined: Thu Dec 26, 2002 2:19 pm

Post by ariear »

You can also...
4. DSPrepareJob
Post Reply