Search⌘ K
AI Features

Adding Notifications to Mastery and the Boundary

Explore how to integrate notifications into an Elixir project by modifying the quiz lifecycle events. Understand how to send notifications when a quiz starts and ends through process message passing, improving your skill in managing communication within OTP boundaries and enhancing user interaction feedback.

Adding a notification to start the quiz

Let’s add the notification to start_quiz in proctor.ex:

C++
def start_quiz(quiz, now) do
Logger.info "Starting quiz #{quiz.fields.title}..."
notify_start(quiz)
QuizManager.build_quiz(quiz.fields)
Enum.each(quiz.templates, &add_template(quiz, &1))
timeout = DateTime.diff(quiz.end_at, now, :millisecond)
Process.send_after(
self(),
{:end_quiz, quiz.fields.title, quiz.notify_pid},
timeout)
end

In start_quiz, we have two changes to make:

  • After we log the start of the quiz, we call our new notify_start function, where we’ll do the notification via send.

  • Next, ...