muesli / beehive

A flexible event/agent & automation system with lots of bees 🐝
GNU Affero General Public License v3.0
6.32k stars 325 forks source link

Scripting Bee #243

Open mkrauser opened 5 years ago

mkrauser commented 5 years ago

I would love to see a Scripting-Bee where you can invoke Scripts (PHP, JS, Go, Perl, ...).

I thought about this a lot, and in my opinion it is too much effort to include the scripting languages within beehive. Instead the respective interpreters/compilers should be installed on the host system.

The Event-Data can be provided as command-line parameters or via StdIn.

What would you think of this:

Additional 3rd party libraries for the respective language should be usable.

Do you see any red flags or have more ideas or other input for such a bee?

Thanks for the good work!

prologic commented 5 years ago

Why not just do what Consul Template does and just allow arbitrary binary/scripts/whatever to be used as Bees. Define the interface as a set of required Stdin/Stdout and. Why should this have anything specific to do with any interpreted scripting language intepreter?

muesli commented 5 years ago

You can already use the ExecBee to communicate via stdin/out and run arbitrary binaries, but that's obviously just an action you can execute. You couldn't trigger any defined events, and you can't keep a script running for continuous communication.

Some more food for thought:

The same concept could be used for arbitrary scripts that communicate via a (well-defined) JSON protocol over stdin/out. At that point we're getting dangerously close to a full-blown RPC interface, which we could use to turn all hives into external processes that just communicate with the core, and are language agnostic by design.

The more hives we are integrating and offering, the more valuable such an approach would become. It makes it easier to keep the core slim and - ideally - lets the user only build & run those hives they actually want to use. It would also mean you can build & update a Hive on-the-fly, without re-building & re-starting all of Beehive.

mkrauser commented 5 years ago

You are right, all this can already be done with the ExecBee. But there would be some boilerplate-code which is required everytime (read from StdIn and convert the json-string).

What I'm proposing is a Bee where the customer can enter some Code and this is executed when the action is triggered. The boilerplate-code should be pre-pended to this script automatically to provide the input already parsed and converted. Kind of like the Handler-Argument in AWS-Lambda.

My Idea did initially not include long running scripts for continuous communication or triggering other Events, although this sounds interesting.

RPC also has lots of benefits, but this goes way outside of my idea.

mkrauser commented 5 years ago

btw: Zapier offers something similar: Code on Zapier

prologic commented 5 years ago

Looks like it supports execution of Javascript as triggers. If we went down that route we could use otto.

CalmBit commented 5 years ago

That might not be a terrible idea. For all that I don't like about javascript, it's a great scripting language.

muesli commented 5 years ago

@mkrauser Ok, understood. A defined protocol for scripts to receive & return values via a JSON interface is certainly a good idea. This will stand or fall by the quality of the provided documentation, though, so please try to keep that in mind!

prologic commented 5 years ago

Recommend the use of Protobuf here to:

Even if we marshal it as JSON -- that's fine.

mkrauser commented 5 years ago

@prologic That sound really nice, I will have a look at it. Thank you!