Events 'collect-app-status' and 'collect-unit-status'

Event > List of events > Ops events > collect-app-status and collect-unit-status

Source: CollectStatusEvent

The collect-app-status and collect-unit-status events are produced not by Juju but Ops.

The events are emitted on the charm, starting from ops 2.7, before the framework exits. The goal is to offer the charm a chance to uniformly set the application or unit status based on its internal state after processing the Juju event that triggered this execution.

Contents:

Emission sequence

The collect-app-status and collect-unit-status events are fired once by the framework after any Juju event is emitted, and before any other framework event is emitted. The -app-status event is for setting application status, and the -unit-status event for setting unit status.

For example, if the unit is processing a config-changed event, the charm will see:

config-changedcollect-unit-statuspre-commitcommit

Observing these events in Ops

To observe the collect-unit-status event:

# in MyCharm.__init__
self.framework.observe(self.on.collect_unit_status, self._on_collect_unit_status)

This will observe the event uniformly across the units of the charm.

To observe the collect-app-status event:

# in MyCharm.__init__
self.framework.observe(self.on.collect_app_status, self._on_collect_app_status)

This will ensure that only the leader unit processes it, and the result becomes the overall application status.

A CollectStatusEvent instance does not expose any specific attributes but exposes an add_status method to automatically manage statuses with different priorities. Read the API reference docs for more information and examples.

Last updated 5 months ago. Help improve this document in the forum.