How I can to get custom options in the `init` function of the Tarantool Cartridge role?

ぃ、小莉子 提交于 2021-01-27 05:14:39

问题


A Tarantool Cartridge role file has a function init.

I want to get my custom options from the instance.yml file. But the opts variable doesn't have it.

How I can do it?


回答1:


Cartridge has a built-in module called "argparse". It parses a few sources of configuration and combines them together:

  • instances.yml or files in /etc/tarantool/conf.d
  • command line arguments
  • environment variables starting with TARANTOOL_

Cartridge uses this module to get various pieces of configuration like the port numbers or maximum allowed memory usage. But it doesn't stop you from putting anything you like in those files, as long as it doesn't clash with built-in parameters.

Here's what you chould have in your init():

local argparse = require('cartridge.argparse')

-- ...

local function init()
    local args = argparse.parse()

    log.info("My parameter: %s", args.my_parameter) -- use anything you want in place of my_parameter
end


来源:https://stackoverflow.com/questions/62040869/how-i-can-to-get-custom-options-in-the-init-function-of-the-tarantool-cartridg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!