DEV Community

KILLALLSKYWALKER
KILLALLSKYWALKER

Posted on

Attack of the Clones: From Endless Notifications to Daily Summaries in Laravel

In our job portal, every time a candidate applied for a job, we sent an email to the recruiter right away.

At first, this was fine. Recruiters got updates quickly. But when more people started applying, recruiters with popular jobs were getting dozens or even hundreds of emails in one day.

Their inbox became full of “clone” emails. Many recruiters felt annoyed and started to ignore the notifications.

We needed a better way.

The answer? Send one daily summary email instead of many small ones.

Too Many Emails

Notification::route('mail', $recruiter->email)
->notify(new ApplicationNotification($application));
Enter fullscreen mode Exit fullscreen mode

This sends one email per application. With 100 applicants → 100 emails. Inbox spam. Recruiters will not happy.

New Way : Daily Summary Notification

Instead of sending one email each time, we gather all applications for a recruiter during the day and send one notification in the evening.

use App\Models\Recruiter;
use App\Models\Application;
use App\Notifications\ApplicationNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class SendDailyApplicationSummary implements ShouldQueue
{
    use Dispatchable, Queueable;

    public function handle()
    {
        Recruiter::chunk(100, function ($recruiters) {
            foreach ($recruiters as $recruiter) {
                $applications = Application::where('recruiter_id', $recruiter->id)
                    ->whereDate('created_at', today())
                    ->get();

                if ($applications->isNotEmpty()) {
                    Notification::route('mail', $recruiter->email)
                        ->notify(new ApplicationNotification($applications));
                }
            }
        });
    }
}

Enter fullscreen mode Exit fullscreen mode

Of course , we need to ensure our ApplicationNotification has been updated also with logic to summary the daily application .

Once we have this now we just set schedule for it using laravel schedule

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
      $schedule->job(new SendDailyApplicationSummary)->dailyAt('18:00');
    }
}
Enter fullscreen mode Exit fullscreen mode

Now every recruiter of company will receive one single email summary instead of multiple email for applications that they receive on that day .

Closing

See how simple it is with Laravel’s Notification, Scheduler, and Queues.We can send application updates properly as a daily summary, without spamming recruiters.
This way, recruiters stay happy and not annoying with our job portal notification .

Top comments (2)

Collapse
 
xwero profile image
david duymelinck

send one notification in the evening.

That feels like torture, sending people more work at the end of the day.
You know there are people who are going to read that and act on it.

A friendlier way would be to send the applications of yesterday as a summary in the morning.
Then the people can review it with a cup of coffee or tea. And it can be the start of a productive day.

Sorry for my tangent, using queues and scheduler is a great solution.

Collapse
 
killallskywalker profile image
KILLALLSKYWALKER

we try do weekly summary one time , but support getting question why no application notification daily hahahahahha @xwero