Tribe Support

Tribe Support's Articles

Rastin Mehr

Rastin Mehr

November 13 2017

How to configure Anahita mail notification crons

In this article I going to explain how to configure mail notification crons in your Anahita installation without getting into a Rouge Notifications situation. A rouge notification is when your server suddenly emails out hundreds of email notifications to your users. It could happen to any web application that sends out mail notifications. 

It's ok if you occasionally and unintentionally blow things up here and there in your project, but it is not nice when other people are affected as a result. A rouge notification scenario is one of them!

Here is how to do it right:

The default installation of Anahita can send mail notifications, but the approach isn't scalable if you have hundreds or thousands of followers for an actor profile. In this case you'd need to create a cron that continuously processes pending notifications. You'll also need another cron to clear your servers mail queue, because some of your members might have bad emails and these message add up over time.

PLEASE NOTE: do make a database backup before proceeding, just in case you made a mistake and needed to recover your data.

1. Disabling existing notifications

Before switching Anahita to use crons for notifications, it is a good idea to mark all notifications as sent. This is to make sure no pending notifications suddenly get sent out like a nest of hornets poked with a stick. So run this query to set all notifications to sent. Note that status=1 means the notification has been sent already.

Loading ...

It's ok if your users don't receive a few notifications. You don't want to take any chances of your notifications going rouge.

2. Using a cron to process notifications

Please Note: You may be using crond or just good old fashion crontab on your server. If you don't know what crons are and how to set them up on your server, google it and learn it.

Now go to Site Settings > Apps > Notifications and set the option Use Crons to YES

Now you need to setup a cron for processing mail notifications every 3 minutes:

Loading ...

Notice that we set the max execution time to 60 seconds or 1 minute and running the cron every 3 minute. It is important to space apart the notification processing to avoid any possible complications. In the meantime we want some responsiveness from the time something is posted and the time people receive notifications.

3. Cleaning up the email queue

Some of your members may have invalid or bad emails - I know right! - that means whenever a batch of mail notifications are created, the ones with good email get sent out and the ones with bad email accumulate in the mail queue. You can find that out by type the command:

$ mailq | grep -c "^[A-F0-9]"

and that will return the number of mails in the queu. You can setup a cron to flush the queue, let's say, every hour:

Loading ...

Nice to know commands

What if you found yourself in a rouge notification situation and your server has created a large bulk of notifications and sending them out. First of all stay focused and don't panic. Use these commands as needed:

To see mail queue, enter:

$ mailq

To see number of mails in the queue, enter:

$ mailq | grep -c "^[A-F0-9]"

To remove all mail from the queue, enter:

$ postsuper -d ALL

To remove all mail from the deferred queue, enter:

$ postsuper -d ALL deferred

To read the last 5 lines of your cron log and making sure things are working, enter:

$ tail -f -n 5 /var/log/cron

That's it folks. If you know any tips or you want to add something to this article, please post a comment.  

#Notifications #MailNotifications #RogueNotifications

Gregg N-A liked this

Additional Information

Powered by Anahita