diff --git a/app/Jobs/Commands/Eve/ProcessSendEveMailJob.php b/app/Jobs/Commands/Eve/ProcessSendEveMailJob.php index 4b8e832d0..e6b6f80d8 100644 --- a/app/Jobs/Commands/Eve/ProcessSendEveMailJob.php +++ b/app/Jobs/Commands/Eve/ProcessSendEveMailJob.php @@ -37,10 +37,10 @@ class ProcessSendEveMailJob implements ShouldQueue /** * Retries - * With new rate limiting, we shouldn't use this timeout + * With new rate limiting, we need a retry basis versus timeout basis * @var int */ - //public $retries = 3; + public $retries = 5; private $sender; private $body; @@ -166,6 +166,9 @@ class ProcessSendEveMailJob implements ShouldQueue //Allow 4 jobs per minute, and implement a rate limited backoff on failed jobs $rateLimitedMiddleware = (new RateLimited()) + ->enabled() + ->key('psemj') + ->connectionName('redis') ->allow(4) ->everySeconds(60) ->releaseAfterOneMinute() diff --git a/app/Jobs/Commands/Eve/ProcessSendEveMailJobRL.php b/app/Jobs/Commands/Eve/ProcessSendEveMailJobRL.php index 6bbc199de..6ab663ed3 100644 --- a/app/Jobs/Commands/Eve/ProcessSendEveMailJobRL.php +++ b/app/Jobs/Commands/Eve/ProcessSendEveMailJobRL.php @@ -42,13 +42,6 @@ class ProcessSendEveMailJobRL implements ShouldQueue */ //public $retries = 3; - /** - * Middleware for the job - * - * @var \Spatie\RateLimitedMiddleware\RateLimited - */ - private $middleware; - private $sender; private $body; private $recipient; @@ -126,9 +119,11 @@ class ProcessSendEveMailJobRL implements ShouldQueue * */ public function middleware() { - - //Allow 4 jobs per minute, and implement a rate limited backoff on failed jobs + $rateLimitedMiddleware = (new RateLimited()) + ->enabled() + ->key('PSEMJ') + ->connectionName('redis') ->allow(4) ->everySeconds(60) ->releaseAfterOneMinute() @@ -137,6 +132,27 @@ class ProcessSendEveMailJobRL implements ShouldQueue return [$rateLimitedMiddleware]; } + private function OtherCode() { + //Can also specify middleware when dispatch a job. + //SomeJob::dispatch()->through([new SomeMiddleware]); + + //Current method of creating job handle with redis throttle + /** + * public function handle() + * { + * Redis::throttle('key')->allow(10)->every(60)->then(function () { + * // Job logic... + * }, function () { + * // Could not obtain lock... + * return $this->release(10); + * }); + * } + */ + + + + } + /* * Determine the time at which the job should timeout. *