I am experimenting with the cron scheduling feature in the volttron agent development to a run a volttron control agent at a specific time.
How to do I call the configure
method when agent starts via the onstart
method on my agent.py file?
@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.
"""
This is my configure
method. I know this question is most likely blatantly obvious but what is config_name, action, contents
that I am supposed to pass through in onstart
to call the configure
method?
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!')
My config file is config
:
{
"cron_schedule": "50 13 * * *"
}