View difference between Paste ID: EBqTjR4m and 2dAwWuZX
SHOW: | | - or go back to the newest paste.
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->releaseThrottle());
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-
   public function releaseThrottle()
29+
30
           return Intercom::update()
31-
       // some logging stuff
31+
32
   }
33
 
34
   public function throttleExceeded()
35
   {
36
       $this->release(60);
37
   }
38
}