From eaf59c80ea5cbee58baa4fe3e3a089a0264f2389 Mon Sep 17 00:00:00 2001 From: James Garner Date: Fri, 27 Sep 2024 15:37:09 +1200 Subject: [PATCH 1/3] docs: explicitly document that collect-status is is run on *every* hook --- ops/charm.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ops/charm.py b/ops/charm.py index 46ee2db6b..58810ed44 100644 --- a/ops/charm.py +++ b/ops/charm.py @@ -1100,7 +1100,12 @@ class CollectStatusEvent(LifecycleEvent): way after the end of every hook, it should observe the :attr:`collect_app_status ` or :attr:`collect_unit_status ` event, - respectively. + respectively. Note that this event is triggered at the end of *every* hook, + so any observer of these events will be run on every hook, regardless of + whether the charm observes that hook event. For example, even if you don't + observe :attr:`config_changed `, your collect status + observer will run at the end of every :attr:`config_changed ` + event. The framework will trigger these events after the hook code runs successfully (``collect_app_status`` will only be triggered on the leader From dbd04670c95cb99bacb5fcb3fc0a38fe97cee08c Mon Sep 17 00:00:00 2001 From: James Garner Date: Fri, 27 Sep 2024 16:01:07 +1200 Subject: [PATCH 2/3] docs: make this more concise Co-authored-by: Tony Meyer --- ops/charm.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ops/charm.py b/ops/charm.py index 58810ed44..56cf7d5f7 100644 --- a/ops/charm.py +++ b/ops/charm.py @@ -1100,12 +1100,10 @@ class CollectStatusEvent(LifecycleEvent): way after the end of every hook, it should observe the :attr:`collect_app_status ` or :attr:`collect_unit_status ` event, - respectively. Note that this event is triggered at the end of *every* hook, - so any observer of these events will be run on every hook, regardless of - whether the charm observes that hook event. For example, even if you don't - observe :attr:`config_changed `, your collect status + respectively. Note that observing the specific hook event is not required. For example, even + if you don't observe :attr:`config_changed `, your collect status observer will run at the end of every :attr:`config_changed ` - event. + event, as well as all others. The framework will trigger these events after the hook code runs successfully (``collect_app_status`` will only be triggered on the leader From f3f3e76b4cdb300af011c95abf7525ca1acdd534 Mon Sep 17 00:00:00 2001 From: James Garner Date: Mon, 30 Sep 2024 11:25:22 +1300 Subject: [PATCH 3/3] docs: make this even more concise --- ops/charm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ops/charm.py b/ops/charm.py index 56cf7d5f7..42c94b292 100644 --- a/ops/charm.py +++ b/ops/charm.py @@ -1100,14 +1100,13 @@ class CollectStatusEvent(LifecycleEvent): way after the end of every hook, it should observe the :attr:`collect_app_status ` or :attr:`collect_unit_status ` event, - respectively. Note that observing the specific hook event is not required. For example, even - if you don't observe :attr:`config_changed `, your collect status - observer will run at the end of every :attr:`config_changed ` - event, as well as all others. + respectively. The framework will trigger these events after the hook code runs successfully (``collect_app_status`` will only be triggered on the leader - unit). If any statuses were added by the event handler using + unit). This happens on every Juju event, whether it was + :meth:`observed ` or not. + If any statuses were added by the event handler using :meth:`add_status`, the framework will choose the highest-priority status and set that as the status (application status for ``collect_app_status``, or unit status for ``collect_unit_status``).