Functions Lifecycle Operations

Couchbase Functions offers seven distinct lifecycle operations: add, deploy, undeploy, debug, delete and export-import.

eventing fun lifecycle

The following table presents supported lifecycle operations with their Function status.

Lifecycle/
Function Status

Deploy

Undeploy

Deploy

NA

Paused state. Tracking of data mutations is temporarily paused.

Undeploy

Re-deployed state. Restarts tracking of data mutations.

NA

Editing

Not supported. Deployed Functions cannot be edited.

Supported. Undeployed Functions can be edited.

Delete

Not supported. Deployed Functions cannot be deleted.

Supported. Undeployed Functions can be deleted.

Adding a Function

To add a new Function, proceed as follows:

  1. From the Couchbase Web Console > Eventing page, click ADD FUNCTION.

  2. In the ADD FUNCTION dialog, for individual Function elements, provide the below information:

    Elements Description

    Source Bucket

    This bucket listens to data mutations. For more information, see Source Buckets.

    Metadata Bucket

    This bucket stores artifacts and checkpoint information. For more information, see Metadata Buckets.

    Function Name

    Provide a name for the Function you are creating.

    Description

    Provide a small description for the Function you are creating. This field is optional.

    Settings

    The available Function settings are:

    • Log Level: Select log granularity. Options are Info, Error, Warning, Debug.

    • Workers : Specify the number of worker threads to be allocated. The default value is 3.

    • Script Timeout : Specify the number of seconds that should elapse before the Function script times out. The default value is 60.

    Note: All three attributes are not global, but are Function-specific.

    Bindings

    A binding allows separating of environment specific variables from the handler code. For more information, see Bindings

  3. Click Next: Add Code. The Function name dialog appears. The Function name dialog initially contains a placeholder code block. You will substitute your actual Function code in this block. The above step completes the procedure for adding a Function.

  4. To return to the Eventing screen, click Eventing.

  5. Click on the Function name. Additional controls are now displayed:
    The controls are:

    1. Delete: Deletes the Function from the system.

    2. Export: Exports the Function as a JSON document.

    3. Deploy: Deploys the Function and makes it active across the cluster.

    4. Edit JavaScript: Allows edits to be made on the Function handler code, in an edit dialog.

Deploying a Function

The deploy operation activates a Function. A Function must be in a deployed status to process data mutations. Couchbase Server performs a source validation step before Function deployment.

To deploy a Function, proceed as follows:

  1. From the Couchbase Web Console > Eventing page.

  2. Click on the Function name. Additional controls get displayed.

  3. Click Deploy. This displays the Confirm Deploy Function dialog. The Feed Boundary determines whether documents previously in existence needs to be included in the Function’s activities. Everything and From now are two options. The Everything option invokes a Function on all the data present in the cluster. The From now option invokes a Function during future instances of data mutation, post Function deployment.

  4. Click Deploy Function. This deploys the Function and returns you to the main Eventing screen. The UI indicates that the Function is now deployed and running.

Undeploying a Function

Couchbase Server terminates processing of data mutations when you undeploy a Function. Post undeployment, workers along with any other runtime resources acquired by the Function are either released or they get terminated.

The undeployed state can be logically termed as a temporary state of a Function. An undeployed Function can be deployed to resume tracking of data mutations, modified to make edits to the Function handler code, or can be deleted.

To edit the handler code, you must undeploy a Function.

Before you undelpoy a Function, ensure to make informed decisions regarding Function Backlogs. The Function Backlog information is available in Statistics section.

To undeploy an existing Function, proceed as follows:

  1. From the Couchbase Web Console > Eventing page.

  2. Click on the deployed Function name. Additional controls get displayed.

  3. Click Undeploy. This undeploys the Function and returns you to the main Eventing screen.

The Function lifecycle operations and the Eventing rebalance operation
are mutually exclusive. The Eventing rebalance operation fails when a Function
lifecycle operation is currently in progress. Likewise, when the Eventing
rebalance operation is in progress, you cannot perform a Function lifecycle operation.

Debugging a Function

For information on debugging, refer to Debugging section.

Exporting and Importing of Functions

For easy porting of code across environments an export-import option is provided.

Third-party defined Function definitions cannot be imported. Couchbase Server supports importing of exported Couchbase Functions.

To export and import Functions, proceed as follows:

  1. Navigate to the Couchbase Web Console > Eventing page.

  2. To export a Function:

    1. Click on the deployed Function name. Additional controls get displayed.

    2. Click Export. The Function definition is exported in a JSON format.

  3. To import an exported Function:

    1. Navigate to the Couchbase Web Console > Eventing page.

    2. From the Eventing page, click IMPORT. The import button is available at the screen top right-corner.

    3. Browse and select an exported file. Click Open. The Add Function dialog gets displayed.

    4. In the Add Function dialog, few fields are pre-populated. Make relevant changes if needed.

  4. Click Next: Add Code.

  5. In the Function handler code page, click Save.

Deleting a Function

Couchbase Server supports deleting of undeployed Functions. A delete operation removes the Function from the cluster. Deleting a Function is an irreversible operation. When a Function gets deleted, all indexes are dropped, all metadata information in general and timer related metadata in particular, gets deleted from the cluster.

To delete a Function, proceed as follows:

  1. From the Couchbase Web Console > Eventing page.

  2. Click on the undeployed Function name. Additional controls get displayed.

  3. Click Delete. This displays the Confirm Delete Function dialog.

  4. Click Delete Function. This deletes the Function and returns to the main Eventing screen.