This is the ThingsDB documentation for version v0, click here for the latest version!

deploy_module

Deploy a module on all nodes. The module must be configured first, using the new_module() function. This function is used to write the module data (or plain python code) to the module. After deploying the code, the module will be restarted on every node.

Before deploying a module, it is strongly recommended to use a development environment before deploying the module into production.

This function generates an event.

Function

deploy_module(name, data)

Arguments

Argument Type Description
name str (required) Name of the module to deploy the new code for.
data str/bytes/nil (required) Data for the module. When nil, no data will be overwritten but the module will be restarted on all nodes. This might be useful if you want to force a module restart on all nodes. Type str is only allowed for Python modules.

Return value

Returns nil. You might want to use module_info(..) to check if the module is successfully running. If not, the node logging might give you additional information about the cause of the error.

Example

Create a new python module ECHO and deploy the code using deploy_module(..):

// Create a new (python) module
new_module('ECHO', 'echo.py');

// Deploy the module code
deploy_module('ECHO',
"from timod import start_module, TiHandler, LookupError


class Handler(TiHandler):

    async def on_config(self, cfg):
        pass  # no config required

    async def on_request(self, req):
        if 'message' not in req:
            raise LookupError('missing `message` in request')

        return req['message']


if __name__ == '__main__':
    start_module('echo', Handler())

");

Return value in JSON format

null