Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmanos committed Dec 24, 2014
0 parents commit b754325
Show file tree
Hide file tree
Showing 14 changed files with 507 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 Mark Manos

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# AWS SQS push queue driver for Laravel 4

This package provides a laravel queue driver with support for AWS SQS push queues. This technique is used by the AWS Elastic Beanstalk worker tier environments.

## Installation Via Composer

Add this to you composer.json file, in the require object:

```javascript
"mmanos/laravel-sqspushqueue": "dev-master"
```

After that, run composer install to install the package.

Add the service provider to `app/config/app.php`, within the `providers` array.

```php
'providers' => array(
// ...
'Mmanos\SqsPushQueue\SqsPushQueueServiceProvider',
)
```

## Configuration

Update the existing `queue.php` config file and change the sqs driver to be `sqspush`. This driver will use the existing sqs config properites (`key`, `secret`, etc...).

#### Dependencies

The following dependencies are needed for this package:

* AWS: `aws/aws-sdk-php`
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "mmanos/laravel-sqspushqueue",
"description": "An AWS SQS push queue driver for Laravel 4.",
"keywords": ["laravel", "queue", "aws", "sqs", "push", "elasticbeanstalk", "elastic", "beanstalk", "worker"],
"authors": [
{
"name": "Mark Manos",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.*"
},
"suggest": {
"aws/aws-sdk-php": "2.*"
},
"autoload": {
"psr-0": {
"Mmanos\\SqsPushQueue\\": "src/"
}
},
"minimum-stability": "stable",
"license": "MIT"
}
Empty file added public/.gitkeep
Empty file.
41 changes: 41 additions & 0 deletions src/Mmanos/SqsPushQueue/Connector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace Mmanos\SqsPushQueue;

use Illuminate\Http\Request;
use Illuminate\Queue\Connectors\ConnectorInterface;
use Aws\Sqs\SqsClient;
use Illuminate\Queue\SqsQueue;

class Connector implements ConnectorInterface {

/**
* The current request instance.
*
* @var \Illuminate\Http\Request
*/
protected $request;

/**
* Create a new Iron connector instance.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
public function __construct(Request $request)
{
$this->request = $request;
}

/**
* Establish a queue connection.
*
* @param array $config
* @return \Illuminate\Queue\QueueInterface
*/
public function connect(array $config)
{
$sqs = SqsClient::factory($config);

return new Queue($sqs, $this->request, $config['queue']);
}

}
123 changes: 123 additions & 0 deletions src/Mmanos/SqsPushQueue/Job.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php namespace Mmanos\SqsPushQueue;

use Illuminate\Queue\Jobs\Job as AbstractJob;
use Aws\Sqs\SqsClient;
use Illuminate\Container\Container;
use Exception;

class Job extends AbstractJob {

/**
* The Amazon SQS client instance.
*
* @var \Aws\Sqs\SqsClient
*/
protected $sqs;

/**
* The Amazon SQS job instance.
*
* @var array
*/
protected $job;

/**
* Create a new job instance.
*
* @param \Illuminate\Container\Container $container
* @param \Aws\Sqs\SqsClient $sqs
* @param array $job
* @return void
*/
public function __construct(Container $container,
SqsClient $sqs,
array $job)
{
$this->sqs = $sqs;
$this->job = $job;
$this->container = $container;
}

/**
* Fire the job.
*
* @return void
*/
public function fire()
{
$body = json_decode($this->getRawBody(), true);
$this->resolveAndFire($body);
}

/**
* Get the raw body string for the job.
*
* @return string
*/
public function getRawBody()
{
return $this->job['Body'];
}

/**
* Release the job back into the queue.
*
* @param int $delay
* @return void
*/
public function release($delay = 0)
{
throw new Exception('Release');
}

/**
* Get the number of times the job has been attempted.
*
* @return int
*/
public function attempts()
{
return (int) $this->job['Attributes']['ApproximateReceiveCount'];
}

/**
* Get the job identifier.
*
* @return string
*/
public function getJobId()
{
return $this->job['MessageId'];
}

/**
* Get the IoC container instance.
*
* @return \Illuminate\Container\Container
*/
public function getContainer()
{
return $this->container;
}

/**
* Get the underlying SQS client instance.
*
* @return \Aws\Sqs\SqsClient
*/
public function getSqs()
{
return $this->sqs;
}

/**
* Get the underlying raw SQS job.
*
* @return array
*/
public function getSqsJob()
{
return $this->job;
}

}
Loading

0 comments on commit b754325

Please sign in to comment.