title: Max Attempts Exceeded Exception queue laravel
body: <p>I have created an application to send e-mails to more than one user but I am facing a problem when dealing with a large number of recipients.</p>
  <p>The error appears in a <code>failed_jobs</code> table</p>
  <pre><code>Illuminate\Queue\MaxAttemptsExceededException: App\Jobs\ESender has been attempted too many times or run too long. The job may have previously timed out. in D:\EmailSender\vendor\laravel\framework\src\Illuminate\Queue\Worker.php:649
  </code></pre>
  <p>and this is <code>payload</code> in <code>failed_jobs</code> table</p>
  <pre><code>{&quot;uuid&quot;:&quot;ff988083-c1da-4d20-a2e3-c2a10e154c79&quot;,&quot;timeout&quot;:9000,&quot;id&quot;:&quot;j2Lz0Ro0bkJpqwxKWTxC3Tiii71iE6Cm&quot;,&quot;data&quot;:{&quot;command&quot;:&quot;O:16:\&quot;App\\Jobs\\ESender\&quot;:13:{s:7:\&quot;timeout\&quot;;i:9000;s:12:\&quot;receiver_obj\&quot;;O:45:\&quot;Illuminate\\Contracts\\Database\\ModelIdentifier\&quot;:4:{s:5:\&quot;class\&quot;;s:12:\&quot;App\\Receiver\&quot;;s:2:\&quot;id\&quot;;i:6;s:9:\&quot;relations\&quot;;a:0:{}s:10:\&quot;connection\&quot;;s:5:\&quot;mysql\&quot;;}s:16:\&quot;sender_all_hosts\&quot;;O:45:\&quot;Illuminate\\Contracts\\Database\\ModelIdentifier\&quot;:4:{s:5:\&quot;class\&quot;;s:15:\&quot;App\\SenderHosts\&quot;;s:2:\&quot;id\&quot;;a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}s:9:\&quot;relations\&quot;;a:0:{}s:10:\&quot;connection\&quot;;s:5:\&quot;mysql\&quot;;}s:11:\&quot;message_obj\&quot;;O:45:\&quot;Illuminate\\Contracts\\Database\\ModelIdentifier\&quot;:4:{s:5:\&quot;class\&quot;;s:12:\&quot;App\\Messages\&quot;;s:2:\&quot;id\&quot;;i:36;s:9:\&quot;relations\&quot;;a:0:{}s:10:\&quot;connection\&quot;;s:5:\&quot;mysql\&quot;;}s:7:\&quot;counter\&quot;;i:1;s:3:\&quot;job\&quot;;N;s:10:\&quot;connection\&quot;;N;s:5:\&quot;queue\&quot;;N;s:15:\&quot;chainConnection\&quot;;N;s:10:\&quot;chainQueue\&quot;;N;s:5:\&quot;delay\&quot;;N;s:10:\&quot;middleware\&quot;;a:0:{}s:7:\&quot;chained\&quot;;a:0:{}}&quot;,&quot;commandName&quot;:&quot;App\\Jobs\\ESender&quot;},&quot;displayName&quot;:&quot;App\\Jobs\\ESender&quot;,&quot;timeoutAt&quot;:1594841911,&quot;maxExceptions&quot;:null,&quot;maxTries&quot;:null,&quot;job&quot;:&quot;Illuminate\\Queue\\CallQueuedHandler@call&quot;,&quot;delay&quot;:null,&quot;attempts&quot;:1}
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ye47j.png" rel="noreferrer">see the cmd error here.</a></p>
  <p>parts of code:</p>
  <p>#1</p>
  <pre><code>class ESender implements ShouldQueue
  {
      use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  
  
      /**
       * The number of times the job may be attempted.
       *
       * @var int
       */
      public $tries = 100;
  
      /**
       * The number of seconds the job can run before timing out.
       *
       * @var int
       */
      public $timeout = 9999999;
  
       ...more code...
  }
  </code></pre>
  <p>#2</p>
  <pre><code>public function handle(){
      Redis::throttle('key')-&gt;allow(1)-&gt;every(20)-&gt;then(function () {
           //send email
             ..... more code .....
  
          }, function () {
              // Could not obtain lock...
              return $this-&gt;release(10);
          });
      }
  </code></pre>
  <p>and this is my configuration:</p>
  <p><code>queue.php</code>:</p>
  <pre><code>'redis' =&gt; [
              'driver' =&gt; 'redis',
              'connection' =&gt; 'default',
              'queue' =&gt; env('REDIS_QUEUE', 'default'),
              'retry_after' =&gt; 9000,
              'block_for' =&gt; null,
          ],
  </code></pre>
  <p><code>.env</code></p>
  <pre><code>BROADCAST_DRIVER=log
  CACHE_DRIVER=file
  QUEUE_CONNECTION=database
  SESSION_DRIVER=file
  SESSION_LIFETIME=300
  REDIS_CLIENT = predis
  REDIS_HOST=127.0.0.1
  REDIS_PASSWORD=null
  REDIS_PORT=6379
  QUEUE_DRIVER=database
  </code></pre>