Solved
Forum Discussion
bojanvelevski
4 years agoValued Contributor
Try this Python script:
# Import the interface required by the Script snap.
from com.snaplogic.scripting.language import ScriptHook
import time
class TransformScript(ScriptHook):
def __init__(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
# The "execute()" method is called once when the pipeline is started
# and allowed to process its inputs or just send data to its outputs.
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()
time.sleep(20)
outDoc = 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")
# The "cleanup()" method is called after the snap has exited the execute() method
def cleanup(self):
self.log.info("Cleaning up")
# The Script Snap will look for a ScriptHook object in the "hook"
# variable. The snap will then call the hook's "execute" method.
hook = TransformScript(input, output, error, log)
You can change the delay in the Time.sleep() function. Currently is 20 seconds.
darshthakkar
4 years agoValued Contributor
Great solution, thanks @bojanvelevski
- Abhishek_1173 years agoNew Contributor II
Hi darshthakkar
I tried the code,but its taking more than 20 seconds.