forked from maknz/slack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gaurav
committed
May 26, 2017
1 parent
7978697
commit f657eb9
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Razorpay\Slack\Jobs; | ||
|
||
use Razorpay\Slack\Client; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Bus\Queueable; | ||
//use Illuminate\Contracts\Bus\SelfHandling; | ||
|
||
class SlackJob implements ShouldQueue | ||
{ | ||
use InteractsWithQueue, SerializesModels, Queueable; | ||
|
||
protected $payload; | ||
|
||
const MAX_RETRY_ATTEMPTS = 10; | ||
|
||
const RELEASE_WAIT_TIMEOUT = 120; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$this->payload = $payload; | ||
} | ||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
if ($this->attempts() >= self::MAX_RETRY_ATTEMPTS) | ||
{ | ||
$this->delete(); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
$app = App::getFacadeRoot(); | ||
|
||
$app['slack']->sendPayload($this->payload); | ||
|
||
$this->delete(); | ||
} | ||
catch (\Throwable $e) | ||
{ | ||
$this->release(self::RELEASE_WAIT_TIMEOUT); | ||
} | ||
} | ||
} | ||
} |