volttron agent开发调用configure方法onstart

volttron agent development call configure method onstart

我正在试验 volttron agent development 中的 cron 调度功能,以便在特定时间 运行 volttron 控制代理。

当代理通过 agent.py 文件上的 onstart 方法启动时,如何调用 configure 方法?

@Core.receiver("onstart")
def onstart(self, sender, **kwargs):
    """
    This is method is called once the Agent has successfully connected to the platform.
    This is a good place to setup subscriptions if they are not dynamic or
    do any other startup activities that require a connection to the message bus.
    Called after any configurations methods that are called at startup.
    Usually not needed if using the configuration store.
    """

这是我的configure方法。我知道这个问题很可能是显而易见的,但是我应该在 onstart 中通过什么 config_name, action, contents 来调用 configure 方法?

def configure(self, config_name, action, contents):
    """
    Called after the Agent has connected to the message bus. If a configuration exists at startup
    this will be called before onstart.

    Is called every time the configuration in the store changes.
    """
    config = self.default_config.copy()
    config.update(contents)

    _log.debug("*** [Setter Agent INFO] *** - Configuring CRON to schedule Agent")


    try:
        cron_schedule = str(config["cron_schedule"])


    except ValueError as e:
        _log.error("ERROR PROCESSING CONFIGURATION: {}".format(e))
        return


    self.cron_schedule = cron_schedule
    self.core.schedule(cron(self.cron_schedule), self.raise_setpoints_up)
    _log.info(f'*** [Setter Agent INFO] *** -  raise_setpoints_up CRON schedule from onstart sucess!')

我的配置文件是 config:

{

  "cron_schedule": "50 13 * * *"

}

此函数“应该”与配置存储相关联。请参阅 https://volttron.readthedocs.io/en/main/platform-features/config-store/agent-configuration-store.html

config_name 是配置存储中被修改的位置。因此,当您通过命令或我在下面给出的示例中的“设置”调用之一更新配置存储中的配置条目时,将使用更新后的数据调用此函数。

通过代理处理配置存储的相关方法是https://volttron.readthedocs.io/en/main/platform-features/config-store/agent-configuration-store.html#configuration-subsystem-agent-methods

# From your agent onstart method

#self.vip.config.set( config_name, contents, trigger_callback=False ) 

# Using True will have the configstore callback (call the configure function)
self.vip.config.set('my_config_file_entry', {"an": "entry"}, trigger_callback=True)

当然,您可以在 onstart 方法中自己使用该函数,但这不是设计的方式。

确保此功能有效的另一点是确保您在代理初始化函数中有订阅,以便正确触发回调。