Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor
Aug 29, 2012
Laurence Tratt If nothing's needed to be sent in a cycle, reset all externals last s…
…uccessful sends.

Since we can't tell if they've come back up or not, it's sensible to reset
them, and ensure that the next time there's a message to be sent, each is
retried.
4110d4b
Laurence Tratt If no messages have been sent, there's no need to poll every 5s.
This is unnecessarily wasteful; poll every 60s in such circumstances, which
is quite sufficient.
b20e3a7

Showing 1 changed file with 37 additions and 8 deletions. Show diff stats Hide diff stats

  1. +37 8 extsmaild.c
45 extsmaild.c
@@ -485,6 +485,22 @@ bool cycle(Conf *conf, Group *groups, Status *status)
485 485 status->spool_loc = 0;
486 486 status->any_failure = false;
487 487 status->last_success = status->last_notify_failure = time(NULL);
  488 + if (num_successes == 0) {
  489 + // Since we haven't sent anything, we don't really know if our
  490 + // externals are alive or not. We therefore assume they are
  491 + // all live or have come back to life. Update the last_success
  492 + // accordingly to force them to be used the next time there are
  493 + // messages to send.
  494 + Group *cur_group = groups;
  495 + while (cur_group != NULL) {
  496 + External *cur_ext = cur_group->externals;
  497 + while (cur_ext != NULL) {
  498 + cur_ext->last_success = time(NULL);
  499 + cur_ext = cur_ext->next;
  500 + }
  501 + cur_group = cur_group->next;
  502 + }
  503 + }
488 504 }
489 505 else
490 506 status->any_failure = true;
@@ -1113,17 +1129,30 @@ int main(int argc, char** argv)
1113 1129
1114 1130 openlog(__progname, LOG_CONS, LOG_MAIL);
1115 1131
1116   - int poll_wait = INITIAL_POLL_WAIT;
  1132 + int unsuccessful_wait = INITIAL_POLL_WAIT;
1117 1133 while (1) {
1118   - bool success = cycle(conf, groups, &status);
  1134 + bool all_sent = cycle(conf, groups, &status);
1119 1135
1120   - if (!success && conf->notify_failure_interval > 0
  1136 + if (!all_sent && conf->notify_failure_interval > 0
1121 1137 && time(NULL) >
1122 1138 status.last_notify_failure + conf->notify_failure_interval) {
1123 1139 do_notify_failure_cmd(conf, &status);
1124 1140 status.last_notify_failure = time(NULL);
1125 1141 }
1126 1142
  1143 + // If all messages have been sent successfully (or if there were no
  1144 + // messages to send), we don't want to wait INITIAL_POLL_WAIT
  1145 + // seconds - it's far too wasteful. We might as well wait a full
  1146 + // MAX_POLL_WAIT. If anything hasn't been sent, we wait
  1147 + // unsuccesful_wait seconds (a gradually increasing int from
  1148 + // INITIAL_POLL_WAIT to MAX_POLL_WAIT).
  1149 +
  1150 + int poll_wait;
  1151 + if (all_sent)
  1152 + poll_wait = MAX_POLL_WAIT;
  1153 + else
  1154 + poll_wait = unsuccessful_wait;
  1155 +
1127 1156 // On platforms that support an appropriate mechanism (such as kqueue
1128 1157 // or inotify), we try and send messages as soon as we notice changes
1129 1158 // to spool_dir/msgs. We also wake-up every 'poll_wait' seconds to
@@ -1156,12 +1185,12 @@ int main(int argc, char** argv)
1156 1185 sleep(poll_wait);
1157 1186 #endif
1158 1187
1159   - if (success)
1160   - poll_wait = INITIAL_POLL_WAIT;
  1188 + if (all_sent)
  1189 + unsuccessful_wait = INITIAL_POLL_WAIT;
1161 1190 else {
1162   - poll_wait *= 2;
1163   - if (poll_wait > MAX_POLL_WAIT)
1164   - poll_wait = MAX_POLL_WAIT;
  1191 + unsuccessful_wait *= 2;
  1192 + if (unsuccessful_wait > MAX_POLL_WAIT)
  1193 + unsuccessful_wait = MAX_POLL_WAIT;
1165 1194 }
1166 1195 }
1167 1196 }

No commit comments for this range

Something went wrong with that request. Please try again.