Skip to content

Commit

Permalink
added slackjob class
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed May 26, 2017
1 parent 7978697 commit f657eb9
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Jobs/SlackJob.php
@@ -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);
}
}
}
}

0 comments on commit f657eb9

Please sign in to comment.