Gateway Scripts Module Always Run on Gateway

Hello there,

I have written a module that has a few scripts in it. I always want to have these run on the Gateway (since it needs access to the Gateways filesystem) even if I go and run the script from the Script Console. Is this possible?

You would have to add a message handler and then use system.util.sendMessage to invoke this from the Script Console. You can't just have it run in the gateway scope all the time.

1 Like

Thats what I was hoping to avoid doing.

What is the proper way to build a message handler in a module? I seem to have skipped it over in the documentation.

I assume you mean script module, but message handlers belong to a project, not a module. You just write code in the module that you then invoke from the handler.

It helps if you understand that the scripting environments (aka “scope” or “context”) in the gateway, designer, and Vision clients are not connected to each other. They run locally wherever they are. To get scripts to run in other contexts, you must send messages.

It also helps if you understand that the gateway has multiple scopes all running at the same time, with some overlap. Each project has a scripting scope, and the top-level names automatically present (like script module names) vary by project scope. Perspective scope adds a layer of additional names and functions on top of the corresponding project scope.

Doing it that way means that it would not be easily reproducible without coping and pasting code between different gateways/projects (which is what I am trying to prevent).

Is there a way to create a handler which can run “globally” that is created from the module itself? I guess I am just trying to make it as easy as possible for others to use this project. I guess if it really came down to it, I could create some sort of jetty handler that should be able to handle this I guess.

You are posting in Module Development. Which means your module has access to all script engines (managers), and can inject any infrastructure you like under the system.* namespace. Do this for all script managers and all scopes will have them.

You also have access to custom RPC from Designer and Vision scopes, so functions called in those scopes can seamlessly perform a callout to the gateway to execute.

{ Hmmm. Wrong category? “Module Development” == “Module SDK Development” }