php - What is the best way to send prioritized mails in a email queue? -


millions of mails inserted mysql table "emailqueue" following fields,

  1. id - bigint(20)
  2. email_address - varchar(300)
  3. message - text
  4. status - enum('pending','prioritized','processing','processed')
  5. created_datetime - datetime
  6. sent_datetime - datetime

generally rows inserted 'pending' status high priority mails such forget/reset password inserted 'prioritized' in status column.

the cron job run every hour , send mails loop batch of 20000 mails in every loop until finish sending emails. want send prioritized mails first can add email queue when cron job running.

what best approach achieve this? i'm not sure if stackoverflow place ask question, not sure better place. in advance.

if ignore "add while cron running" sec, select 'prioritized' first:

order field(status, "prioritized"), id asc 

this'll sort rows status=prioritized first order id. more info/examples here.


adding them while cron running more difficult, becomes logic challenge. if select * emails order field(status, "prioritized"), id asc select data in data at time of selecting. if items added after you've run query, wont in returned set of data.

to want, you'll need break code smaller selections:

$continueprocesss = false; $current = 0; $itemsperbatch = 25; while( $continueprocesss ){     $query = "select * emails order field(status, 'prioritized'), id asc`                limit $current,$itemsperbatch";     $result = yourquerymethod($query);     if( $result->num_rows===0 ){         $continueprocesss = false;         break;     } else{        $current += $itemsperbatch; // next round, skip $itemsperbatch rows     } } 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -