08-11-2023 11:59 PM
How can i delay a process according to our needs, is there any snap to perform wait operation?
I tried with script snap, mentioned there to delay for 15 seconds,but its taking more time than 15 seconds.
CODE
Solved! Go to Solution.
08-17-2023 07:50 AM
The code you shared does wait 15 seconds, but it waits on each input document. This means that if you have 10 input documents, you will have a wait time of 150 seconds.
I am not sure where you set up your script in your pipeline, but you have to make sure you are either waiting 15 seconds before the input documents start processing, or waiting 15 seconds after each input document has been processed. You can do this if you amend your code, specifically the time.sleep() function.
If you want your script to wait for 15 seconds before it starts processing the input documents, the you can use the following code in your execute() function:
def execute(self):
self.log.info("Executing Transform script")
time.sleep(15)
while self.input.hasNext():
try:
# Read the next input document, store it in a new dictionary, and write this as an output document.
inDoc = self.input.next()
outDoc = {
'original' : inDoc
}
self.output.write(inDoc, outDoc)
except Exception as e:
errDoc = {
'error' : str(e)
}
self.log.error("Error in python script")
self.error.write(errDoc)
self.log.info("Script executed")
Or, if you want to wait for 15 seconds after all documents have been
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
try:
# Read the next input document, store it in a new dictionary, and write this as an output document.
inDoc = self.input.next()
outDoc = {
'original' : inDoc
}
self.output.write(inDoc, outDoc)
except Exception as e:
errDoc = {
'error' : str(e)
}
self.log.error("Error in python script")
self.error.write(errDoc)
time.sleep(15)
self.log.info("Script executed")
The only difference is that you need to put time.sleep(15) before the while loop or after the while loop, this of course depends on your case.
08-20-2023 07:40 PM
I sincerely appreciate your excellent explanation @j_angelevski ,Your contribution has been truly valuable. Thank you very much!