Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-6543

Add onUnscheduled support for ExecuteGroovyScript Processor

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • None
    • 1.11.0
    • Extensions
    • None

    Description

      The ExecuteGroovyScript processor is great, and it is great to have the support for onStart and onStop methods.  However, I often find myself wishing there were also a way to take some action when the processor is unscheduled.  That would let the groovy code to make decisions about whether or not to get() another flowfile.  

       

      I think it should be as easy as 

      diff --git a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
      index c35ab392d..eead4bc07 100644
      --- a/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
      +++ b/nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
      @@ -27,6 +27,7 @@ import org.apache.nifi.annotation.documentation.CapabilityDescription;
       import org.apache.nifi.annotation.documentation.SeeAlso;
       import org.apache.nifi.annotation.documentation.Tags;
       import org.apache.nifi.annotation.lifecycle.OnScheduled;
      +import org.apache.nifi.annotation.lifecycle.OnUnscheduled;
       import org.apache.nifi.annotation.lifecycle.OnStopped;
       import org.apache.nifi.components.PropertyDescriptor;
       import org.apache.nifi.components.RequiredPermission;
      @@ -264,6 +265,14 @@ public class ExecuteGroovyScript extends AbstractProcessor {
                   throw new ProcessException("onStart failed: " + t, t);
               }
           }
      +    @OnUnscheduled
      +    public void onUnscheduled(final ProcessContext context) {
      +        try {
      +            callScriptStatic("onUnscheduled", context);
      +        } catch (Throwable t) {
      +            throw new ProcessException("onUnscheduled failed: " + t, t);
      +        }
      +    }
       
           @OnStopped
           public void onStopped(final ProcessContext context) {
       

      But this is my first attempt to change Nifi; I defer to others.

      Attachments

        Activity

          People

            mattyb149 Matt Burgess
            mmwagner Michael Wagner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Time Spent - 50m Remaining Estimate - 1h 10m
                1h 10m
                Logged:
                Time Spent - 50m Remaining Estimate - 1h 10m
                50m