A Snap opposite to "Exit" snap

It may be useful to have a Snap that instead of raising an Error when too many documents are received, raises an error when too few documents are received in the input - including zero docs.

E.g., If the expectation is for there to be input documents when a scheduled task is run and there isn’t, an error can be signaled.

TK

There are workarounds for it.

For instance you can check for the incoming documents easily and verify if
you are getting any parameters or documents.

$.hasOwnProperty(‘required element name’) and do the action based on that.

Thanks & Regards,
Naveen

Another workaround is to use something similar to this in the Script snap (using Python). You can then use the error view and combine with the Exit snap.

from com.snaplogic.scripting.language import ScriptHook
import java.util

class TransformScript(ScriptHook):
    def __init__(self, input, output, error, log):
        self.input = input
        self.output = output
        self.error = error
        self.log = log

    def execute(self):
        count = 0
        try:
            while self.input.hasNext():
                in_doc = self.input.next()
                self.output.write(in_doc)
                count += 1
        except:
            pass
        if count < 1:
            self.error.write({"error":'No documents received!'})
            
hook = TransformScript(input, output, error, log)

Alternatively, if you just want to kill the pipeline, you can substitute self.error.write({"error":'No documents received!'}) with raise Exception("No documents received!")

That is the generally the approach that we use in the couple of pipelines that require this behavior.

Thanks for the feedback.

TK