Queue mechanism to stop processing jobs#24
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesYou may notice some variations in coverage metrics with the latest Coverage engine update. For more details, visit the documentation |
.env.example
Outdated
|
|
||
| MAIL_CHARSET=utf-8 | ||
|
|
||
| MAX_ATTEMPTS_DEFAULT=10 |
There was a problem hiding this comment.
10 its a lot of to be set as default, you can change this to be 3
There was a problem hiding this comment.
@ani2amigos as we have a config file to deal with the envs and load them all at once, you can move this $_ENV['MAX_ATTEMPTS_DEFAULT'] there so we can easily have access to all env setup
|
|
||
| $timestamp = $mailJob->getTimeToSend(); | ||
| $delay = max(0, $timestamp - time()); | ||
| $pheanstalk->delete($mailJob->getPheanstalkJob()); |
There was a problem hiding this comment.
pheanstalk has a method to re-queue the job, the release as it was set.
set the algorithm to be like:
- if not finished, increase the attempt number;
- if not overtaking the number of attempts defined, use release method;
- if it's finished or reached the attempts limit, delete
| if (!$mailJob->isCompleted() && $mailJob->getAttempt() <= $_ENV['MAX_ATTEMPTS_DEFAULT']) { | ||
| $timestamp = $mailJob->getTimeToSend(); | ||
| $delay = max(0, $timestamp - time()); | ||
| // add back to the queue as it wasn't completed maybe due to some transitory error |
There was a problem hiding this comment.
remove any comment from code not related to docs
| $sql = sprintf($sqlText, $this->tableName); | ||
| $query = $this->getConnection()->getInstance()->prepare($sql); | ||
| $query->bindValue(':id', $mailJob->getId()); | ||
| } else { |
There was a problem hiding this comment.
avoid using else when writing the algs, return query execute instead, them outside the if, the other case:
if($mailJob->getAttempt() > $_ENV['MAX_ATTEMPTS_DEFAULT']){
$sqlText = 'DELETE FROM mail_queue WHERE id = :max_attempt;';
$sql = sprintf($sqlText, $this->tableName);
$query = $this->getConnection()->getInstance()->prepare($sql);
$query->bindValue(':id', $mailJob->getId());
return $query->execute();
}
$sqlText = 'UPDATE `%s`
SET `attempt`=:attempt, `state`=:state, `timeToSend`=:timeToSend, `sentTime`=:sentTime
WHERE `id`=:id';
... rest of your code
No description provided.