One Star

How to Wait for an Email(attachment)?

The prerequisite for a job is the receipt of an email. The email arrives once each day, however the time varies by 6-8 hours. The email attachment is saved to the file system (tPOP) and processed. (see job image)
The tPOP component fails if the filters find no matches in the Outlook inbox...which is correct behavior. But then someone needs to watch for the email to restart the job.
I thought perhaps the scheduler might have options that would help.. but I see nothing there.
I tried putting a tInfiniteLoop --- OnSubjobOK in front of tPOP, but the tPOP never executes.
What is the approach to set up a job that will wait/watch for an email, run to completion and not trigger again until the next day?
Thanks in advance,
Mark
1 REPLY
Seven Stars

Re: How to Wait for an Email(attachment)?

Your design should be:
parent job: tInfiniteLoop --iterate--> tJava --iterate--> tLoop --iterate--> tRunJob --main--> tJavaRow
|
--OnComponentOK--> tSleep
In tInfiniteLoop have the wait: 0
In tJava have the code: globalMap.put("TimeStarted",System.currentTimeMillis());
In tLoop have:
- Loop Type: While
- Declaration: "boolean processed = false"
- Condition: "!processed"
- Iteration: ""
In tRunJob, call the child job with "Die on child error" unchecked and Copy Child Job Schema
In tJavaRow have the code: processed=input_row.processed;
In tSleep have the pause: 86400-(System.currentTimeMillis()-(Long)globalMap.get("TimeStarted"))/1000
child job: Everything in your job from tPop onwards --OnSubjobOK--> tFixedFlowInput --main--> tBufferOutput
|
--OnSubjobError--> tSleep --OnSubjobOK--> tFixedFlowInput --main--> tBufferOutput
In both tFixedFlowInputs have the schema:
- Column: processed
- Type: boolean
In the OK tFixedFlowInput have the Value: true
In the Error tFixedFlowInput have the Value: false
In tSleep have the pause you want before trying to find the email again that day.
What this does is allow the tPop to fail in the child job without compromising the daily loop in the parent. The success or failure of tPop is passed to the parent to allow it to try that day again if the email is not found (after an appropriate interval). Once the child is successful, the parent waits until the same time the next day as it originally started.
Note that you could use any scheduler to control the daily repeat rather than doing it in the job itself as I have shown, in which case your parent job would just be: tLoop --iterate--> tRunJob --main--> tJavaRow