Page 1 of 1
call another job from job control and wait if it is running
Posted: Tue Jun 27, 2006 4:48 pm
by catiechase
I'm trying to use a job control in one job to call another job. I want to wait (sleep) if that other job is running. Multple instances won't really work, so i need to have the controlling job wait to call the job once it has finished.
I'd like to just look up the job status on that job, but I don't have a handle since it was called by a separate process.
The next thing I tried was to run the job DSAttacheJob and if it didn't work, wait (sleep) and try again later. I'm just not quite sure how to make that work.
Posted: Tue Jun 27, 2006 7:49 pm
by kcbland
Welcome! You can get the status using the command line program dsjob without needing a job handle. Otherwise, you can try to use DSAttach and see the value returned from a DSGetJobInfo and see if the return value is DSJE.BADHANDLE. I never tried it, but the DS BASIC documentation has to be correct, right?
Posted: Tue Jun 27, 2006 7:50 pm
by kcbland
Wait a minute, what do I mean welcome? You've been lurking quite a awhile. How about: Thanks for piping up!
Posted: Tue Jun 27, 2006 11:39 pm
by sb_akarmarkar
Did you try DSWaitForJob(JobHandle) ?
Thnaks,
Anupam
Posted: Wed Jun 28, 2006 1:10 am
by ray.wurlod
DSAttachJob() is necessary before issuing the run request with DSRunJob(). So retrying that function isn't going to help; it's still attached to the controller while it's running.
Try creating a new server job, open its job properties then the Job Control tab. Select a job from the drop down list and click Add Job. Inspect the generated code; it will show you how DSWaitForJob is used.
If you need to use Sleep for some other reason (for example a busy loop that does other things in the meantime) then you need to write a loop that checks to see if the job is still running.
Code: Select all
Loop
While DSGetJobStatus(hJob, DSJ.JOBSTATUS) = DSJS.RUNNING
* do other things
Sleep 2 ; * sleep for two seconds
Repeat ; * loop exits once status is no longer "running"
This is not a perfect solution, but will get you started.
Posted: Wed Jun 28, 2006 6:24 am
by kcbland
The stated issue is that if ControlJob#1 has attached and started TransformJob, how can ControlJob#2 attached to TransformJob and see its status? I don't believe two jobs can have a job handle for the same job simultaneously, but maybe I'm wrong.
Posted: Wed Jun 28, 2006 12:43 pm
by catiechase
I'm doing this in the job control of a job, so it is in the BASIC. I can't user the dsjob command from there. But your other suggestion works - I get a return value of 0 if the job is already running. THANKS!!!!
kcbland wrote:Welcome! You can get the status using the command line program dsjob without needing a job handle. Otherwise, you can try to use DSAttach and see the value returned from a DSGetJobInfo and see if the return value is DSJE.BADHANDLE. I never tried it, but the DS BASIC documentation has to be correct, right?
Posted: Wed Jun 28, 2006 1:03 pm
by kcbland
Okay, but you can always issue system command line commands via a CALL DSExecute(....). You can run dsjob as a command. Search the forum for DSExecute for ways folks have used it.