# Adhoc Code

One of the early motivators for LogBus was support for quick, one-off logic without having to write a custom plugin and all of the technical debt that could incur. Enter the js plugin. This simple plugin allows the user to easily manipulate events with a JavaScript function defined right in the pipeline definition.

# Example

This example demonstrates how simple it is to sprinkle in some logic, in this case making sure that this pipeline is only operating on its partition of the data.

pipeline:
  partition:
    module: js
    inputs: [some-data]
    config:
      function: !!js/function >-
        function(event) {
            if (event.id % this.env.PARTITIONS === this.env.WORKER) {
              return event
            }
        }

LogBus does not infantalize its users the way some utilties in this space do. It trusts that you know what you are doing, provides some primitives to help accomplish your goals, and then tries its best to stay out of your way. While some may exclaim that "eval() is evil!", being secure by default is a non-goal.

# this Context

Unless otherwise stated in the plugin's documentation, pipeline-defined functions will have the following this object defined:

  • config: a reference to this stage's config
  • util: the nodejs util module
  • moment: the moment library
  • hostname: the os.hostname() function
  • env: process.env