Feature Request: Add delay, wait or sleep snap

I think it will be very good to have a snap that will wait for a preconfigured period of time before continuing to execute next snaps.

For example, I am invoking some pipeline and it fails for some reason. I want to re-invoke it again but after 30 seconds(configurable with parameter).

So, I guess it would be good to have a snap that will wait or even better pause the pipeline execution for some period of time and then continue from the point where it is paused.

You can put a sleep in script snap using any script language - Javascript, python or Ruby

I already tried using timeout in JavaScript, but it was not working. So I implemented another script that is doing this:

var date = new Date();
do { curDate = new Date(); }
while(curDate-date < Interval);

which is not ideal solution.

Basically, a snap that will pause the pipeline for that period of time and continue where it is paused will be best option for this instead of doing a script that is in running state.

Try this. I used Ruby. It is simple

sleep 5

will sleep for 5 seconds.

wait_2017_09_13.slp (6.9 KB)

2 Likes

Tried using the same script more than once in single pipeline and through an error,

Script:class MyScript
    # Import the interface required by the Script snap.
    include com.snaplogic.scripting.language.ScriptHook
    attr_reader :log, :input, :output, :error
    def initialize(log, input, output, error)
        @log = log
        @input = input
        @output = output
        @error = error
    end

    # 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()
        while input.hasNext() do
            begin
                # Read the next document, wrap it in a map and write out the wrapper
                doc = input.next()
                wrapper = {
                 "original" => doc
                }
                sleep (5/100)
            
                log.info("Executed Ruby script")
                output.write(doc, wrapper)
            
            rescue => e
                log.error("Bad Rublet " + e.message)
                errWrapper = {
                    "errMsg" => e.message
                }
                error.write(errWrapper)
            end
        end
        
        
    end
end

# The Script Snap will look for a ScriptHook object in the "hook"
# variable.  The snap will then call the hook's "execute" method.
$hook = MyScript.new($log, $input, $output, $error) does not satisfy the contract

Resolution:
Add a global variable named 'hook' to the script that is instantiated to the class that implements ScriptHook interface

Reason:
Script does not have a variable named 'hook'

anyone has solved this?