Skip to main content

Charm library for handling unit status with contexts

Project description

charm-lib-contextual-status

Contextual status handling for charmed operators.

The goal of this library is to provide a mechanism for code within charm libraries to raise status conditions, such as Blocked or Waiting statuses, without relying on exceptions or other constructs that might otherwise interfere with the flow control of Python code.

This is accomplished by having the charm create a background status context with:

import charms.contextual_status as status

with status.context(self.unit):
    some_lib.do_work()

Within a status context, it's possible for code to emit status conditions:

status.add(MaintenanceStatus("Doing something"))

if some_failure_condition:
    status.add(BlockedStatus("Failed to do something"))

When a MaintenanceStatus is added to a status context, it is immediately set as the unit status, so that the charm can provide status updates during in-progress work.

When a BlockedStatus or WaitingStatus is added to a status context, it is stored within the context for later. Multiple statuses can be added this way.

When a status context is closed, the unit status is set based on a simple priority system: Blocked status is higher precedence than Waiting, and within those groups, the earliest emitted status is preferred. If no Blocked or Waiting statuses were emitted within the context, then the unit status is set to Active.

The on_error decorator can be used to set status when an exception is raised:

@status.on_error(BlockedStatus("Failed to do something"))
def do_something():
    status.add(MaintenanceStatus("Doing something"))

    # ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

charms_contextual_status-0.0.1.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

charms_contextual_status-0.0.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file charms_contextual_status-0.0.1.tar.gz.

File metadata

  • Download URL: charms_contextual_status-0.0.1.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for charms_contextual_status-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0ad9d6796a035fed39f53c6a8a8711ffbd8167d025e6e72490317835d3b83b0a
MD5 3d59d1516c57ed0481672a718d7d8a7d
BLAKE2b-256 73a3d19b24ba65a712cc031e04d9f8f289f4cea1665a207effd2b92a8ff90a07

See more details on using hashes here.

File details

Details for the file charms_contextual_status-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for charms_contextual_status-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1a0d0a76439eb5d008d44424fe1b09eab73c6e6ad964b546c727b3b10195efe
MD5 56f1e2472a7ca4e5cad2536ca938ae7b
BLAKE2b-256 e10e70b4bbe6e2fa9fdf9c9191249d8ee1439a4a3ef185f57c3f62030f9fe23d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page