Skip to content

Notifications

Rubhan Azeem edited this page Oct 8, 2021 · 28 revisions

Details about our notification sub-system.

Workflow

  • An Event gets stored in the database
  • clockwork periodically schedules a SendEventEmailsJob every 30 seconds.
  • SendEventEmailsJob goes over the Event table and
    • EventMailer sends email about Event that have a email EventSubscription
    • NotificationService::Notifier creates Notification for all Event that have web/rss EventSubscription
    • Once done Event.mails_sent is set to true so the event subsystem knows we are done and can clean up after itself.

Event

An Event describes things that happen throughout the whole OBS. See the Events docu for details.

EventSubscription

People subscribe to an event by creating an instance of EventSubscription in the database.

A subscription is specific for a User, a Group, a type of Event (eventtype=Event::CommentForPackage), a Role the User might have (receiver_role="maintainer") and the place where it should be displayed (channel=web, channel=instant_email)

The code below will, for instance, create an email subscription for the user henne for all Event::BuildFail events, concerning packages henne is maintainer of.

EventSubscription.create(eventtype: "Event::BuildFail",
                         receiver_role: "maintainer",
                         user: User.find_by(login: 'henne'),
                         channel: "instant_email",
                         enabled: true)

App Wide Default Subscriptions

All EventSubscription instances that have neither the user nor the group attribute set are considered for all users and groups. Those defaults can only be created by OBS admins via the UI. In a fresh OBS installation there are no instances of EventSubscription.

Finding A Subscription For An Event

EventSubscription does not have a direct association with events. OBS uses EventSubscription::FindForEvent to find subscriptions for an event.

EventSubscription::FindForEvent.new(event).subscriptions(channel)

EventSubscription::FindForEvent take event as argument and returns the subscriptions for that event. The process looks like that:

  • For each role, e.g. commenter, maintainer, bugowner, watcher, find the subscribers, e.g. event.commenters
  • Consider the default system wide event subscriptions (user_id=nil, group_id=nil)
  • Skip the the event originator
  • For each subscriber find the EventSubscription and return

Notifications

A Notification is for a specific Event, a specific User (subscriber_id=1) and one or more places where it should be displayed (rss=true, web=false).

All notifications are triggered with the help of SendEventEmailsJob. This job depends on NotificationService::Notifier and this class is further using NotificationService::WebChannel and NotificationService::RSSChannel depending on the subscription channel.

NotificationService::WebChannel

This class takes two arguments an Event and EventSubscription object.

NotificationService::WebChannel.new(event, subscription).call

OBS has two types of notifiables BsRequest and Comment. The workflow for this service is as follows:

  • Check if there is an existing notification exists for the notifiable type
  • If there are existing notifications, delete them
  • Create new notification and assign that to the projects.

NotificationService::RSSChannel

This also takes an Event and EventSubscription object as an argument.

NotificationService::RSSChannel.new(event, subscription).call

The purpose of this class is to check if the notification does not exist already for an RSS channel, then create one and assign it to the notification's projects.

Clone this wiki locally