Skip to content

Commit 0612625

Browse files
authored
Merge pull request #968 from bramley/process_queue_delay
When using domain throttling, apply delay only when email was sent
2 parents 268b612 + d38983c commit 0612625

File tree

1 file changed

+41
-43
lines changed

1 file changed

+41
-43
lines changed

public_html/lists/admin/actions/processqueue.php

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,13 +1080,15 @@ function sendEmailTest($messageid, $email)
10801080
}
10811081
$now = time();
10821082
$interval = $now - ($now % DOMAIN_BATCH_PERIOD);
1083-
if (!isset($domainthrottle[$throttleDomain]) || !is_array($domainthrottle[$throttleDomain])) {
1083+
if (!isset($domainthrottle[$throttleDomain])
1084+
|| $domainthrottle[$throttleDomain]['interval'] < $interval) {
1085+
// new throttle domain or a new interval for existing domain
10841086
$domainthrottle[$throttleDomain] = array(
1085-
'interval' => '',
1087+
'interval' => $interval,
10861088
'sent' => 0,
10871089
'attempted' => 0,
10881090
);
1089-
} elseif (isset($domainthrottle[$throttleDomain]['interval']) && $domainthrottle[$throttleDomain]['interval'] == $interval) {
1091+
} else {
10901092
$throttled = $domainthrottle[$throttleDomain]['sent'] >= DOMAIN_BATCH_SIZE;
10911093
if ($throttled) {
10921094
++$counters['send blocked by domain throttle'];
@@ -1170,17 +1172,47 @@ function sendEmailTest($messageid, $email)
11701172
// tried to send email , process succes / failure
11711173
if ($success) {
11721174
if (USE_DOMAIN_THROTTLE) {
1173-
if ($domainthrottle[$throttleDomain]['interval'] != $interval) {
1174-
$domainthrottle[$throttleDomain]['interval'] = $interval;
1175-
$domainthrottle[$throttleDomain]['sent'] = 1;
1176-
} else {
1177-
++$domainthrottle[$throttleDomain]['sent'];
1178-
}
1175+
++$domainthrottle[$throttleDomain]['sent'];
11791176
}
11801177
++$counters['sent'];
11811178
++$counters['sent_users_for_message '.$messageid];
11821179
$um = Sql_Query(sprintf('replace into %s (entered,userid,messageid,status) values(now(),%d,%d,"sent")',
11831180
$tables['usermessage'], $userid, $messageid));
1181+
1182+
if ($script_stage < 5) {
1183+
$script_stage = 5; // we have actually sent one user
1184+
}
1185+
1186+
if (isset($running_throttle_delay)) {
1187+
sleep($running_throttle_delay);
1188+
if ($counters['sent'] % 5 == 0) {
1189+
// retry running faster after some more messages, to see if that helps
1190+
unset($running_throttle_delay);
1191+
}
1192+
} elseif (MAILQUEUE_THROTTLE) {
1193+
usleep(MAILQUEUE_THROTTLE * 1000000);
1194+
} elseif (MAILQUEUE_BATCH_SIZE && MAILQUEUE_AUTOTHROTTLE) {
1195+
$totaltime = $GLOBALS['processqueue_timer']->elapsed(1);
1196+
$msgperhour = (3600 / $totaltime) * $counters['sent'];
1197+
$msgpersec = $msgperhour / 3600;
1198+
1199+
//#11336 - this may cause "division by 0", but 'secpermsg' isn't used at all
1200+
// $secpermsg = $totaltime / $counters['sent'];
1201+
$target = (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE) * $counters['sent'];
1202+
$delay = $target - $totaltime;
1203+
1204+
if ($delay > 0) {
1205+
if (VERBOSE) {
1206+
/* processQueueOutput(s('waiting for').' '.$delay.' '.s('seconds').' '.
1207+
s('to make sure we don\'t exceed our limit of ').MAILQUEUE_BATCH_SIZE.' '.
1208+
s('messages in ').' '.MAILQUEUE_BATCH_PERIOD.s('seconds')); */
1209+
processQueueOutput(s('waiting for %.1f seconds to meet target of %s seconds per message',
1210+
$delay, (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE))
1211+
);
1212+
}
1213+
usleep($delay * 1000000);
1214+
}
1215+
}
11841216
} else {
11851217
++$counters['failed_sent'];
11861218
++$counters['failed_sent_for_message '.$messageid];
@@ -1207,40 +1239,6 @@ function sendEmailTest($messageid, $email)
12071239
$GLOBALS['tables']['user'], $useremail));
12081240
}
12091241
}
1210-
1211-
if ($script_stage < 5) {
1212-
$script_stage = 5; // we have actually sent one user
1213-
}
1214-
if (isset($running_throttle_delay)) {
1215-
sleep($running_throttle_delay);
1216-
if ($counters['sent'] % 5 == 0) {
1217-
// retry running faster after some more messages, to see if that helps
1218-
unset($running_throttle_delay);
1219-
}
1220-
} elseif (MAILQUEUE_THROTTLE) {
1221-
usleep(MAILQUEUE_THROTTLE * 1000000);
1222-
} elseif (MAILQUEUE_BATCH_SIZE && MAILQUEUE_AUTOTHROTTLE) {
1223-
$totaltime = $GLOBALS['processqueue_timer']->elapsed(1);
1224-
$msgperhour = (3600 / $totaltime) * $counters['sent'];
1225-
$msgpersec = $msgperhour / 3600;
1226-
1227-
//#11336 - this may cause "division by 0", but 'secpermsg' isn't used at all
1228-
// $secpermsg = $totaltime / $counters['sent'];
1229-
$target = (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE) * $counters['sent'];
1230-
$delay = $target - $totaltime;
1231-
1232-
if ($delay > 0) {
1233-
if (VERBOSE) {
1234-
/* processQueueOutput(s('waiting for').' '.$delay.' '.s('seconds').' '.
1235-
s('to make sure we don\'t exceed our limit of ').MAILQUEUE_BATCH_SIZE.' '.
1236-
s('messages in ').' '.MAILQUEUE_BATCH_PERIOD.s('seconds')); */
1237-
processQueueOutput(s('waiting for %.1f seconds to meet target of %s seconds per message',
1238-
$delay, (MAILQUEUE_BATCH_PERIOD / MAILQUEUE_BATCH_SIZE))
1239-
);
1240-
}
1241-
usleep($delay * 1000000);
1242-
}
1243-
}
12441242
} else {
12451243
++$cannotsend;
12461244
// mark it as sent anyway, because otherwise the process will never finish

0 commit comments

Comments
 (0)