checking 'running' status

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
htrisakti3
Charter Member
Charter Member
Posts: 36
Joined: Thu Jun 10, 2004 11:22 pm

checking 'running' status

Post by htrisakti3 »

I have a main job-control/JC (multi-instance enabled)
This main JC needs to call other Jobs that are NOT multi-instance.
So, I put a logic as follows:
- check status of Job_X
- if it's running, loop & sleep 10seconds & check again
- if Job_X not running, dsprepare & dsrunjob Job_X

now, the problem I found is this:
as the main JC is called by user request or Ctrl-M, multiple requests can be submitted, and most of the time, main JC behaves quite nicely:
sleeping when Job_X is running & run itself subsequently.
in some occasions, though, I noticed that maybe multiple of main_JC are checking the status of Job_X at the very same miliseconds & therefore tried to run simultaneously.

ie: mainJC.1 & mainJC.2 at 00.10 are running Job_X
Strangely, no error was produced, although only 1 result of Job_X can be found.

1. is it possible that checking of JobStatus happen at the very same moment?
2. if multiple jobs tried DSRunJob simultaneously, (even at the very same milisecond) - why didn't end up with error?
3. what do you suggest? if the constraint is that Job_X should really run in serial, not parallel (besides, it only takes 50secs)

thanks
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
If you were actually trying to run the job after it started you would have ended in the later run failing.
If you want to prevent possibly running to extreem cases you might want to add ussage of the DS built in semphore mechanism.
you have 64 locks 0-63 so you can use lock 1 before testing of job status
and unlock 1 after you have run the job.
The down side is that all jobs will wait till the lock is released but if you unlock it right after you finished your check you should suffer no signifcant prformance issues and never have a chance to have such situations occuring in the first place.

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You actually have PSEMNUM of these public semaphores :wink:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
maffan76
Participant
Posts: 110
Joined: Tue Aug 23, 2005 5:27 am

Post by maffan76 »

Hi,
Can i have a code snippet of it as i am new to DS and Basic. as i want to implment the same situation that i have 4 jobs running in parallel and i have 1 table to load in target DB so till 1 point all jobs run in parallel, but once any of the job reaches to this point i want to decide if any of the job is reached to the dependent point it should go first and once that completes it shoudl trigger the next available job for running.

Need your help in this regard.

Thanks in advance.
Regards,
Affan
"Questioning is Half Knowledge"
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'm not sure that this is something that someone 'new to DS and Basic' should be attempting, snippet or no snippet. :?

Is there anyway to build what you need through the GUI - i.e. as a Sequencer job? It may not need to behave exactly as you've outlined in your post, and will be easier to maintain and support that way.

Save the custom job control for when you have a few more miles on the car. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
maffan76
Participant
Posts: 110
Joined: Tue Aug 23, 2005 5:27 am

Post by maffan76 »

the scenario is like this

Sequence1
Load Table1--> Transform(to Load Ready Table1)--
Sequence2 \
Load Table2--> Transform(to Load Ready Table2)-- \
Sequence3 \
Load Tbl3-->Transform(to Load Ready Table3) ------- (Load to target)
Sequence4 /
Load Table4--> Transform(to Load Ready Table4) -----/

Bad Drawing skills :(

so till transform the job can be executed in parallel. but after that when i have to load the target table, i want to control over execution so that i can optimize the loading time as i am loading intially 50 million records and finally 90 million. this logic will simulate the semaphore so that if one job finishes it can pass on the control to the next ready job.

Hope this drawing is of any use.
Regards,
Affan
"Questioning is Half Knowledge"
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

:idea: Wrap the "picture" in Code tags, then use Preview to get it right.

You could use a Routine activity to test whether the job is running, and only fire its trigger if the job is not.

Code: Select all

FUNCTION IsJobRunning(JobName)

Equate RoutineName To "IsJobRunning"

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

hJob = DSAttachJob(JobName, DSJ.ERRNONE)
JobStatus = DSGetJobInfo(hJob, DSJ.JOBSTATUS)
If JobStatus = DSJS.RUNNING
Then

   Ans = 1
   Call DSLogInfo("Job " : Quote(JobName) : " already running.", RoutineName)

End
Else

   If JobStatus < 0
   Then

      Call DSLogWarn('Unable to get status for job ' : Quote(JobName), RoutineName)
      Ans = -1

   End
   Else

      Ans = 0

   End
End

Ignore = DSDetachJob(hJob)

RETURN(Ans)
Fire the trigger only if the routine exits with result 0. That is, the routine executes "OK".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
maffan76
Participant
Posts: 110
Joined: Tue Aug 23, 2005 5:27 am

Post by maffan76 »

Thanks ray,
so i want to wait the routine so that as soon the job previous job gets completed then i can fire that.

i mean if status is running then sleep and check after some time to check the status again.

Thanks in advance.
Regards,
Affan
"Questioning is Half Knowledge"
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Surely you can wrap a loop around it (StartLoop and EndLoop activities) with a Sleep command in it?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
htrisakti3
Charter Member
Charter Member
Posts: 36
Joined: Thu Jun 10, 2004 11:22 pm

Post by htrisakti3 »

but this brings to my original posting..

I have multiple jobs that are queueing to run one particular job.
It already checks for DSJS.RUNNING.
Looking at the log, here's what happened:

10 jobs are queueing to run JobX
at one stage, at the same exact second, this checking triggers multiple jobs to try to run JobX.
(ie: at 00:05 jobA & jobB simultaneously returned false for DSJS.Running, therefore jobA & jobB tried to run JobX)

my conclusion is that checking DSJS.RUNNING is not enough (or maybe there's some slight delay when job switched on, therefore at the same moment, this flag can be true for multiple requests)
Post Reply