Multiple Instances of a server Job.

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Mohanram
Participant
Posts: 9
Joined: Tue Jan 30, 2007 5:21 am

Multiple Instances of a server Job.

Post 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.
Thanks and Regards,
Mohan Ram.T
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
Mohanram
Participant
Posts: 9
Joined: Tue Jan 30, 2007 5:21 am

Post 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 ?
Thanks and Regards,
Mohan Ram.T
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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)
:?
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No, there's nothing automatic about invocations. You will need to control that, probably simplest by incrementing a number each time.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Craig - that chunk of code won't work but will just return the original handle number so it looks like it works
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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...
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I see, you are right. The next part will always fail then... Strange coding
Mohanram
Participant
Posts: 9
Joined: Tue Jan 30, 2007 5:21 am

Post 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.
Thanks and Regards,
Mohan Ram.T
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
Post Reply