Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of Lifecycle Events should be deterministic. #187

Open
davidraker opened this issue Mar 7, 2024 · 0 comments
Open

Order of Lifecycle Events should be deterministic. #187

davidraker opened this issue Mar 7, 2024 · 0 comments

Comments

@davidraker
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The new platform driver needs to load all device configurations together at start time, but still wants to be able to receive individual NEW or UPDATEed device configurations at a later time. In an attempt to accommodate this, a lock variable is set before subscribing to the "devices/" pattern, then the device configurations are loaded manually using vip.config.get('devices/') during the NEW event for "config" (the agent configuration). The lock must then be held long enough that the remaining callbacks for all the initial "NEW" events have finished. Then the lock is released in on_start(). Unfortunately, the "on_start" event is capable of being (and observed to be) fired before the "on_configure" event. This means the lock is released before the NEW configuration callbacks have run.

Describe the solution you'd like
The "on_start" event should deterministically run after "on_configure" or there should be another lifecycle event which does, e.g., "configuration_complete".

Describe alternatives you've considered
Another solution would be to have an additional type of "action" beyond NEW, UPDATE, and DELETE. When the agent starts, a NEW action is sent for each configuration. When these configurations are updated later, an UPDATE action is sent. If a brand new configuration is added, however, a NEW action is sent (though only for the newly added config). For this reason, it is not possible to subscribe only to NEW events which occur after startup nor to only events happening at startup, since they use the same action type (NEW). Really, these two types of NEW actions are distinct. There is (in principle) an INITIAL action which runs when the agent starts and an ADD action which runs when a file is added after the INITIAL actions have completed. While it may not be possible to remove the NEW action, adding INTIAL and ADD actions in parallel with NEW would allow these distinct events to be captured. This alternative would actually be useful even if the lifecycle events are made deterministic, and I would probably advocate that we should do both.

Additional context
A (selective) log of starting the new driver agent with the above described lock. The :

2024-03-07 14:28:30,658 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(125) DEBUG: ########### SETTING LOCK IN __INIT__()
2024-03-07 14:28:30,658 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(126) DEBUG: ########### SUBSCRIBING TO NEW AND UPDATE ON "devices/*"
2024-03-07 14:28:30,668 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(272) ERROR: ########## RUNNING ON_START (REMOVING LOCK).
2024-03-07 14:28:30,678 (volttron-platform-driver-0.2.1rc0 450067) volttron.client.vip.agent.subsystems.configstore(247) DEBUG: Processing callbacks for affected files: {'fake.csv': 'NEW', 'devices/foo': 'NEW', 'devices/bar': 'NEW', 'config': 'NEW'}
2024-03-07 14:28:30,678 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(160) DEBUG: ############# STARTING CONFIGURE_MAIN
2024-03-07 14:28:30,683 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(266) DEBUG: ############ ENDING CONFIGURE_MAIN
2024-03-07 14:28:30,683 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(348) DEBUG: ############ NEW ACTION RAN! UH OH, NO LOCK!!! ##############
2024-03-07 14:28:30,683 (volttron-platform-driver-0.2.1rc0 450067) platform_driver.agent(348) DEBUG: ############ NEW ACTION RAN! UH OH, NO LOCK!!! ##############
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant