Creative commons Attribution-NonCommercial license.
NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
Return a list of emails ready to be delivered. To prevent the scenario
where an email is delivered but not marked as delivered in the database,
email that is in the process of being delivered is marked as "in-progress".
Email that is delivered but never unmarked as "in-progress" requires human
interaction with the system to check what happened.
t = c.prepareStatement("update email set retries=retries+1,in_progress=1,attempt_at=? where uuid=?");
"select uuid,email,retries from email " +
"where in_progress=0 and attempt_at<=? " +
"order by retries, attempt_at " +