Page 1 of 1

Multiple Instances of a server Job.

Posted: Fri Dec 28, 2007 6:41 am
by Mohanram
I have a server job which should execute as multiple instances.So i have enabled the Multiple instances check box from job properties of the same.This mutiple instance job is inturn invoked from some other job using the following routine.

* Reset the Job before Run

hJob1 = DSAttachJob(JobName, DSJ.ERRWARN)
If NOT( hResetJob) Then
-------------------------
-------------------------
End

ErrCode = DSSetDisableProjectHandler(hJob1, @FALSE)
ErrCode = DSSetDisableJobHandler( hJob1, @FALSE)
ErrCode = DSGetJobInfo (hJob1, DSJ.JOBMULTIINVOKABLE)

Result = DSGetJobInfo (hJob1, DSJ.JOBSTATUS)
If (Result = DSJS.RUNFAILED) or (Result = DSJS.STOPPED) or (Result = DSJS.VALFAILED) Then
Result = DSRunJob(hJob1,DSJ.RUNRESET)
ErrCode = DSWaitForJob(hJob1)
End

* Release the handle for the Job
ErrCode = DSDetachJob(hJob1)
* Reset the Job before Run

* Attach the Job and Execute
hJob1 = DSAttachJob(hjob1, DSJ.ERRWARN)
If NOT(hJob1) Then
----------
------------
End

ErrCode = DSGetJobInfo (hResetJob, DSJ.JOBMULTIINVOKABLE)
ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Set parameters or return value
RunFlag=1
End

* Release the handle for the job
ErrCode = DSDetachJob(hJob1)
Ans = RunFlag
-----------------

This multiple instance job should run with different instances,when it is invoked multiple times,but when i actually invoke it number of times i am getting error as 'Job is not in runnable state'.So i understand that its not running as multiple instance job.i am not using any invocation ids for this job.how to call this job,so that, when it runs,it will run with different instance name.Is there any DSRUN function is there to trigger this kind of job.

Posted: Fri Dec 28, 2007 6:46 am
by ArndW
You need to start the job with different instance names, otherwise you will get the error message you have seen. If your job is called "MyJob" then you need to start it with "MyJob.FirstInstanceName" and "MyJob.OtherInstance" and so on.

Posted: Fri Dec 28, 2007 7:11 am
by Mohanram
as i have said,we are not created any invocation Ids separately for the job.We cant guess how many instances of the jobs should be triggered.so we are not gone into that.When i invoke MYJOB,how i will come to know about FirstInstance(Myjob.FirstJobName).just what i am doing right now is Running Job MYJOB. but i need to execute it as Myjob.firstinstanceName..
How i will come to know about FirstinstanceName(x=0,1,2,3,4,5....).Are these needs to be set as job parameters with incremental value? Or Is there any other way so that when run MYJOB, it will automatically run as a different InstancesName attached to itself ?

Posted: Fri Dec 28, 2007 7:13 am
by chulett
Specifically, when you attach to the job:

Code: Select all

hJob1 = DSAttachJob(JobName.InvocationID, DSJ.ERRWARN)
I'm somewhat surprised that the next chunk of code actually works, that you could attach using the old handle again and not the job name:

Code: Select all

* Release the handle for the Job 
ErrCode = DSDetachJob(hJob1) 
* Reset the Job before Run 

* Attach the Job and Execute 
hJob1 = DSAttachJob(hjob1, DSJ.ERRWARN)
:?

Posted: Fri Dec 28, 2007 7:15 am
by chulett
No, there's nothing automatic about invocations. You will need to control that, probably simplest by incrementing a number each time.

Posted: Fri Dec 28, 2007 7:45 am
by ArndW
Craig - that chunk of code won't work but will just return the original handle number so it looks like it works

Posted: Fri Dec 28, 2007 7:58 am
by chulett
But that particular handle has been released, so how can the code that follows actually run the job again? :?

Unless there's some magic snippage in there, critical pieces of code that we are missing...

Posted: Fri Dec 28, 2007 8:02 am
by ArndW
I see, you are right. The next part will always fail then... Strange coding

Posted: Fri Dec 28, 2007 10:15 am
by Mohanram
I have a multiple instance batch job for that i need to create variable InstanceName or Number.so how can i do that. Any suggestions.

Posted: Fri Dec 28, 2007 10:36 am
by ArndW
The instance name isn't too important, it just has to be a unique string. Where do you want to generate this? If from inside DataStage I'd use @DATE:@TIME, assuming you won't be starting several instances within the same second.