Skip to content

SlackReporter

Note

The SlackReporter is still in development and lacks some features, such as specifying the token via environment variables, file attachments, detailed reporting, and reporting of the in-run capsule.

The SlackReporter reports the capsule to a Slack channel. Capsules with the same run name will be reported to the same thread.

It can be created using the capsula.SlackReporter.builder method or the capsula.SlackReporter.__init__ method.

capsula.SlackReporter.builder classmethod

builder(
    *, channel: str, token: str
) -> Callable[[CapsuleParams], SlackReporter]
Source code in capsula/_reporter/_slack.py
@classmethod
def builder(
    cls,
    *,
    channel: str,
    token: str,
) -> Callable[[CapsuleParams], SlackReporter]:
    def build(params: CapsuleParams) -> SlackReporter:
        return cls(phase=params.phase, channel=channel, token=token, run_name=params.run_name)

    return build

capsula.SlackReporter.__init__

__init__(
    *,
    phase: Literal["pre", "in", "post"],
    channel: str,
    token: str,
    run_name: str
)
Source code in capsula/_reporter/_slack.py
def __init__(self, *, phase: Literal["pre", "in", "post"], channel: str, token: str, run_name: str) -> None:
    self._phase = phase
    self._channel = channel
    self._token = token
    self._run_name = run_name

Configuration example

Via capsula.toml

[pre-run]
reporters = [{ type = "SlackReporter", channel = "<channel>", token = "<token>" }]

[in-run] # the reporting of an in-run capsule is not yet supported
reporters = [{ type = "SlackReporter", channel = "<channel>", token = "<token>" }]

[post-run]
reporters = [{ type = "SlackReporter", channel = "<channel>", token = "<token>" }]

Via @capsula.reporter decorator

import capsula

@capsula.run()
@capsula.reporter(capsula.SlackReporter.builder(channel="<channel>", token="<token>"), mode="all")
def func(): ...

Output

It will send a simple message to the specified Slack channel.

For example, for the pre-run capsule:

Capsule run `calculate_pi_n_samples_1000_seed_42_20240923_195220_Tplk` started

For the post-run capsule:

Capsule run `calculate_pi_n_samples_1000_seed_42_20240923_195356_GNDq` completed