我正在试验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
方法。我知道这个问题很可能是显而易见的,但是我应该通过什么来调用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_名称是已修改的配置存储中的位置。因此,当您通过命令或下面我给出的示例中的一个“set”调用更新configstore中的配置条目时,将使用更新的数据调用此函数
通过代理处理配置存储的相关方法是https://volttron.readthedocs.io/en/main/platform-features/config-store/agent-configuration-store.html#configuration-subsystem-agent-methods
当然,在onstart方法中没有任何东西阻止您自己使用该函数,但是它不是这样设计的
要确保这一点起作用的另一点是确保在代理init函数中有订阅,以便正确触发回调
相关问题 更多 >
编程相关推荐