Module Contents



This handler catches all logs and emits a notification


class oioioi.base.notification.NotificationHandler(stream=None)[source]

Bases: logging.StreamHandler

This handler catches all logs and emits a notification if a notification type is set in the extra dictionary, in the log record.

loaded_notifications = False[source]
notification_queue_prefix = _notifs_[source]
last_connection_check = 0[source]
conn_try_interval = 30[source]
classmethod _check_connection()[source]
classmethod _send_notification_message(user, message, repeated=False)[source]
classmethod send_notification(user, notification_type, notification_message, notification_message_arguments)[source]

This function sends a notification to the specified user by sending a message to RabbitMQ.

  • user – User, to whom the notification will be sent.

  • notification_type – A string which describes the notification type.

  • notification_message – A message to show to the notified user, which will be translated by frontend to their language and interpolated using notification_message_arguments. Remember to mark this message to translate, passing it as argument to _() function, so that the message string will be caught to translate.

  • notification_message_arguments

    A map which contains strings to interpolate notification_message and special optional parameters:

    • ”address” – an absolute link

      (starting with http://) to a page related to the notification, where the user can check the details.

    • ”details” – a short information

      for the user about the event.

    • ”popup” – if set the related dropdown will be opened in ui.

classmethod register_notification(notification_type, notification_function)[source]

Register a specific notification handler function for the specified type of notification, that will be executed each time a log with this notification type is processed.


This function is called each time a message is logged.

In our design, it’s role is to invoke a specific handler for corresponding notification type, registered before via register() function by caller.

Specific notification handler should prepare translated message string, split one event for particular users and execute send_notification() function for each user who should be notified.