This recipe sends a Slack message when a process fails or ends with warnings, and an email to the sales team at the end of every run of their daily import.
Install the notifier and the Slack bridge:
composer require symfony/notifier symfony/slack-notifierConfigure the notifier: the failures (high importance) go to Slack and to the admin recipients by email, the
warnings (medium importance) to Slack only:
# config/packages/notifier.yaml
framework:
notifier:
chatter_transports:
slack: '%env(SLACK_DSN)%' # e.g. slack://TOKEN@default?channel=CHANNEL
channel_policy:
high: ['chat/slack', 'email']
medium: ['chat/slack']
low: ['chat/slack']
admin_recipients:
- { email: 'ops@example.com' }The email channel requires symfony/mailer (and its MAILER_DSN).
Enable the notifications for every process, with the default statuses (failed, finish_with_report):
# config/packages/clever_age_ui_process.yaml
clever_age_ui_process:
notification:
enabled: trueThen override it for the processes needing it:
# config/packages/process/app.daily_import.yaml
clever_age_process:
configurations:
app.daily_import:
options:
notification:
statuses: [failed, finish_with_report, finish] # every run
channels: ['email']
recipients:
- { email: 'sales@example.com' }
tasks:
# ...
app.cache_warmup:
options:
notification:
enabled: false
tasks:
# ...- A failed process sends a Slack message and an email to
ops@example.com, e.g.Process "app.purge_authors" failed, with the error, the duration and the log file of the execution. - A process ending with warnings (
Warningor higher logs, seelogs.report_increment_level) sends a Slack message, e.g.Process "app.purge_authors" finished with reported logs, with its report (Warning: 3, Error: 1). - Every run of
app.daily_importsends an email tosales@example.com,app.cache_warmupis never notified.
See notifications for the whole configuration and the
ProcessExecutionEndedEvent to send your own notifications.