Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Throttleable {
- public $throttleKey = 'throttle-key';
- public $throttlePeriod = '60';
- public $throttleAttempts = '60';
- public function throttleRequest(callable $request)
- {
- $response = null;
- Redis::throttle($this->throttleKey)->allow($this->throttleAttempts)->every($this->throttlePeriod)->then(function ()
- {
- $response = $request();
- }, function () {
- return $this->throttleExceeded());
- });
- return $response;
- }
- public function throttleExceeded()
- {
- //
- }
- }
- class UpdateCompany {
- public function handle($event) {
- $response = $this->throttleRequest(function () {
- return Intercom::update()
- })
- }
- public function throttleExceeded()
- {
- $this->release(60);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement