This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
3e087ac
commit 2cb8cca
Showing
6 changed files
with
142 additions
and
86 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
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,94 @@ | ||
<?php | ||
|
||
namespace SimpleSoftwareIO\SqsDisk; | ||
|
||
use Aws\Sqs\SqsClient; | ||
use Illuminate\Support\Arr; | ||
use Illuminate\Container\Container; | ||
|
||
trait SqsDiskBaseJob | ||
{ | ||
use ResolvesPointers; | ||
|
||
/** | ||
* The Amazon SQS client instance. | ||
* | ||
* @var \Aws\Sqs\SqsClient | ||
*/ | ||
protected $sqs; | ||
|
||
/** | ||
* The Amazon SQS job instance. | ||
* | ||
* @var array | ||
*/ | ||
protected $job; | ||
|
||
/** | ||
* Holds the raw body to prevent fetching the file from | ||
* the disk multiple times. | ||
* | ||
* @var string | ||
*/ | ||
protected $cachedRawBody; | ||
|
||
/** | ||
* The disk options for the job. | ||
* | ||
* @var array | ||
*/ | ||
protected $diskOptions; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @param \Illuminate\Container\Container $container | ||
* @param \Aws\Sqs\SqsClient $sqs | ||
* @param array $job | ||
* @param string $connectionName | ||
* @param string $queue | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Container $container, SqsClient $sqs, array $job, $connectionName, $queue, array $diskOptions) | ||
{ | ||
$this->sqs = $sqs; | ||
$this->job = $job; | ||
$this->queue = $queue; | ||
$this->container = $container; | ||
$this->connectionName = $connectionName; | ||
$this->diskOptions = $diskOptions; | ||
} | ||
|
||
/** | ||
* Delete the job from the queue. | ||
* | ||
* @return void | ||
*/ | ||
public function delete() | ||
{ | ||
parent::delete(); | ||
|
||
if (Arr::get($this->diskOptions, 'cleanup') && $pointer = $this->resolvePointer()) { | ||
$this->resolveDisk()->delete($pointer); | ||
} | ||
} | ||
|
||
/** | ||
* Get the raw body string for the job. | ||
* | ||
* @return string | ||
*/ | ||
public function getRawBody() | ||
{ | ||
if ($this->cachedRawBody) { | ||
return $this->cachedRawBody; | ||
} | ||
|
||
if ($pointer = $this->resolvePointer()) { | ||
return $this->cachedRawBody = $this->resolveDisk()->get($pointer); | ||
} | ||
|
||
return parent::getRawBody(); | ||
} | ||
} |
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
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
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,11 @@ | ||
<?php | ||
|
||
namespace SimpleSoftwareIO\SqsDisk; | ||
|
||
use Laravel\Vapor\Queue\VaporJob; | ||
use Illuminate\Contracts\Queue\Job as JobContract; | ||
|
||
class VaporSqsDiskJob extends VaporJob implements JobContract | ||
{ | ||
use SqsDiskBaseJob; | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace SimpleSoftwareIO\SqsDisk; | ||
|
||
use Laravel\Vapor\Console\Commands\VaporWorkCommand as LaravelVaporWorkCommand; | ||
|
||
class VaporWorkCommand extends LaravelVaporWorkCommand | ||
{ | ||
/** | ||
* Marshal the job with the given message ID. | ||
* | ||
* @param array $message | ||
* | ||
* @return \Laravel\Vapor\Queue\VaporJob | ||
*/ | ||
protected function marshalJob(array $message) | ||
{ | ||
$normalizedMessage = $this->normalizeMessage($message); | ||
|
||
$queue = $this->worker->getManager()->connection('sqs'); | ||
|
||
return new SqsDiskJob( | ||
$this->laravel, | ||
$queue->getSqs(), | ||
$normalizedMessage, | ||
'sqs', | ||
$this->queueUrl($message), | ||
config('queue.connections.sqs.disk_options') | ||
); | ||
} | ||
} |