Notifier#
- class rapidtools.gui.Notifier(config: NotificationConfig | None = None, post: Callable[[...], Any] | None = None)[source]#
Bases:
objectSend 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
'email','webhook'or''for an unrecognised target.Deliver
summarytotargetand describe what was done.Send
summarytotothrough the configured relay.Run
send()on a thread and report throughon_result.POST
summaryas JSON tourl.Check that
targetcan be delivered to and return its kind.- 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
targetcan 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
summarytotothrough the configured relay.- Raises:
RuntimeError – When no relay is configured.
SMTPException, OSError – On delivery failure.
- send_webhook(url: str, summary: JobSummary) None[source]#
POST
summaryas JSON tourl.- Raises:
requests.RequestException – On a network error or non-2xx reply.
- send(target: str, summary: JobSummary) str[source]#
Deliver
summarytotargetand describe what was done.- Returns:
str – A log line such as
'Emailed a@b.org.'.- Raises:
ValueError – If the target is unusable.
Exception – Whatever the channel raised.
- send_in_background(target: str, summary: JobSummary, on_result: Callable[[bool, str], None]) Thread[source]#
Run
send()on a thread and report throughon_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.