Notifier#

class rapidtools.gui.Notifier(config: NotificationConfig | None = None, post: Callable[[...], Any] | None = None)[source]#

Bases: object

Send job summaries by email or webhook.

Parameters:
  • config (NotificationConfig) – SMTP relay and link settings.

  • post (Callable | None) – Replacement for requests.post (tests).

Example

>>> notifier = Notifier(NotificationConfig())
>>> notifier.validate_target('not an address')
Traceback (most recent call last):
...
ValueError: Enter an email address or a webhook URL (https://...).

Methods

classify

'email', 'webhook' or '' for an unrecognised target.

send

Deliver summary to target and describe what was done.

send_email

Send summary to to through the configured relay.

send_in_background

Run send() on a thread and report through on_result.

send_webhook

POST summary as JSON to url.

validate_target

Check that target can be delivered to and return its kind.

property email_available: bool#

True when an SMTP relay is configured.

static classify(target: str) → str[source]#

'email', 'webhook' or '' for an unrecognised target.

Example

>>> Notifier.classify('a@b.co'), Notifier.classify('ftp://x')
('email', '')
validate_target(target: str) → str[source]#

Check that target can be delivered to and return its kind.

Raises:

ValueError – For an unrecognised target, or an email address when no SMTP relay is configured.

send_email(to: str, summary: JobSummary) → None[source]#

Send summary to to through the configured relay.

Raises:
send_webhook(url: str, summary: JobSummary) → None[source]#

POST summary as JSON to url.

Raises:

requests.RequestException – On a network error or non-2xx reply.

send(target: str, summary: JobSummary) → str[source]#

Deliver summary to target and describe what was done.

Returns:

str – A log line such as 'Emailed a@b.org.'.

Raises:
send_in_background(target: str, summary: JobSummary, on_result: Callable[[bool, str], None]) → Thread[source]#

Run send() on a thread and report through on_result.

Parameters:
  • target (str) – Email address or webhook URL.

  • summary (JobSummary) – What to send.

  • on_result (Callable[[bool, str], None]) – Called with (ok, message) when delivery finishes.

Returns:

threading.Thread – The started thread.