Eight Stars

Looping on finding a column of a Table

Hi All,

I have a scenario. In One of my Master Job 3 Child Job will run. Now after Each Child Job On SubJobOk in toraclerow an update will run to update status in Database for that Particular Table based upon Maximum(Update_Date). in next tOracleInput I am selecting the status of the Table which ran in the First Child Job and passing to that tjavarow where I am passing that Status Value to a Context. From tjavarow using RunIF condition I am triggering the 2nd ChildJob. Now I am using the RunIF Condition like context.status.equals("Y"). Now I want to do a negetive testing where I want to loop based upon some iteration to check for some time whether Status Value changed to N to Y.My Job Design is like this now

ChildJob1---OnComponentOk---toracleRow(UpdateRunning to change status from N to Y)---OnComponentOk---toracleinput(selecting the status of the table related to ChildJob1)---->tjavarow(Passing the STATUS Value to context)--------RunIF(context value equals "Y")----->ChildJob2

I want to loop now whether the status is still N. It will check whether Status changed to Y or not. Zero Byte file based option can't be taken.

1 ACCEPTED SOLUTION

Accepted Solutions
Eight Stars

Re: Looping on finding a column of a Table

I have did this one with some other approach. What I did was in my tloop component in while I gave loop condition like

i=1(loop will start)

context.status.equals("N")

i++

So untill context.status becomes Y loop will not break.I tested this and was working

 

7 REPLIES
Eight Stars

Re: Looping on finding a column of a Table

Can anyone please help

Fifteen Stars

Re: Looping on finding a column of a Table

I may have completely misunderstood here (I think your description of what is happening is a bit distracting from the problem.... but I may be wrong if I've misunderstood 🙂), but I think you want to loop and try again until your query returns a "Y". Is that right? If so, maybe what I've done with a tLoop here (https://www.rilhia.com/tutorials/using-talend-get-your-spotify-listening-history-facebook) will point you in the right direction. I am looping while a particular field is not null. When it is null, I stop the loop. You could do that while the value returned is "N". You'd need to store that value in the globalMap to do that.
Rilhia Solutions
Eight Stars

Re: Looping on finding a column of a Table

Yes rhall. I want to keep a looping from tjavarow where I will check for Update Status. For Value N it will be on loop and wait for 10mins and again will go to my toracleinput component where I am selecting status from Audit Table and passing that to next tjavarow in context. If time exceeds (e.g 20mins it will exit the loop and send an email.

Fifteen Stars

Re: Looping on finding a column of a Table

There are ways to achieve exactly this using a tLoop and a bit of Java code. However, do you really want to wait 1o minutes in-between checks? A maximum wait time is a good idea, but would it not be better to loop (carry out the checks) every 10 seconds (for example) for 10 mins? Then if after 10 mins there is no change, send the email and end the job?

 

To do this, you could have a configuration similar to below....

 

tJava

|

tLoop ------> t{DB}Input ------>tJavaFlex----RunIf---->{The rest of the logic}

 

1) The tJava would create a globalMap variable (maybe a boolean called "loop") to be used in the tLoop and create a globalMap to hold the start date and time of the tLoop.

2) The tLoop would be set to a While loop. For example ....

((Boolean)globalMap.get("loop"))

3) The DB component would return the status

4) The tJavaFlex would test the status returned AND check the current time against the time variable created in the tJava. If the status is what you want, you can end the tLoop after this iteration by setting "loop" to false. This can also be done if the time limit has expired.

5) Your RunIf can be used to choose to execute further code on this iteration or not.

 

There is a lot of extra logic you will need to fill in for yourself, but this is the basic flow I would advise you use.

Rilhia Solutions
Eight Stars

Re: Looping on finding a column of a Table

Hi rhall,
Yess I want to achieve something like this. If Update doesnot happens then A loop will start.which will check for 10mins in 10secs iteration each. Can you elaborate more as how to go to tdbinput component again if loop does not returned Y.
Fifteen Stars

Re: Looping on finding a column of a Table

Given what I have shown you the tDBInput component will keep firing the same query for each iteration of the loop. You do not need to do anything special to the tDBInput

Rilhia Solutions
Eight Stars

Re: Looping on finding a column of a Table

I have did this one with some other approach. What I did was in my tloop component in while I gave loop condition like

i=1(loop will start)

context.status.equals("N")

i++

So untill context.status becomes Y loop will not break.I tested this and was working