Python Voltron代理开发调用onstart上的配置方法

Python Voltron代理开发调用onstart上的配置方法,python,volttron,Python,Volttron,我正在试验中的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

我正在试验中的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
中调用
configure
方法时,我应该传递什么
config\u名称、操作、内容

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 * * *"

}
此函数“应该”与配置存储相关联。请看

config_名称是已修改的配置存储中的位置。因此,当您通过命令或下面我给出的示例中的一个“set”调用更新configstore中的配置条目时,将使用更新的数据调用此函数

通过代理处理配置存储的相关方法如下

当然,在onstart方法中没有任何东西阻止您自己使用该函数,但是它不是这样设计的


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

Craig您能举一个“代理初始化函数,以便正确触发回调”的示例吗我可以参考的?您可以使用
vpkg init
``设置默认配置以确保立即调用self.configure来设置代理,然后按照代理配置创建代理。self.vip.config.set_default(“config”,self.default_config)#将self.configure挂接到配置文件“config”的更改上。self.vip.config.subscribe(self.configure,actions=[“新建”,“更新”],pattern=“配置”)```
# 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)