Advertisement
Guest User

Untitled

a guest
May 21st, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trait Throttleable {
  2. public $throttleKey = 'throttle-key';
  3. public $throttlePeriod = '60';
  4. public $throttleAttempts = '60';
  5.  
  6. public function throttleRequest(callable $request)
  7. {
  8. $response = null;
  9.  
  10. Redis::throttle($this->throttleKey)->allow($this->throttleAttempts)->every($this->throttlePeriod)->then(function ()
  11. {
  12. $response = $request();
  13. }, function () {
  14. return $this->throttleExceeded());
  15. });
  16.  
  17. return $response;
  18. }
  19.  
  20. public function throttleExceeded()
  21. {
  22. //
  23. }
  24.  
  25. }
  26.  
  27. class UpdateCompany {
  28. public function handle($event) {
  29. $response = $this->throttleRequest(function () {
  30. return Intercom::update()
  31. })
  32. }
  33.  
  34. public function throttleExceeded()
  35. {
  36. $this->release(60);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement