-
Notifications
You must be signed in to change notification settings - Fork 59
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
Showing
8 changed files
with
154 additions
and
5 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,42 @@ | ||
<?php | ||
|
||
namespace Dusterio\AwsWorker\Integrations; | ||
|
||
use Dusterio\AwsWorker\Wrappers\WorkerInterface; | ||
use Dusterio\AwsWorker\Wrappers\DefaultWorker; | ||
use Dusterio\AwsWorker\Wrappers\Laravel53Worker; | ||
|
||
/** | ||
* Class BindsWorker | ||
* @package Dusterio\AwsWorker\Integrations | ||
*/ | ||
trait BindsWorker | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $workerImplementations = [ | ||
'5\.3.*' => Laravel53Worker::class | ||
]; | ||
|
||
/** | ||
* @param $version | ||
* @return mixed | ||
*/ | ||
protected function findWorkerClass($version) | ||
{ | ||
foreach ($this->workerImplementations as $regexp => $class) { | ||
if (preg_match('/' . $regexp . '/', $version)) return $class; | ||
} | ||
|
||
return DefaultWorker::class; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function bindWorker() | ||
{ | ||
$this->app->bind(WorkerInterface::class, $this->findWorkerClass($this->app->version())); | ||
} | ||
} |
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
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,34 @@ | ||
<?php | ||
|
||
namespace Dusterio\AwsWorker\Wrappers; | ||
|
||
use Illuminate\Queue\Worker; | ||
|
||
/** | ||
* Class DefaultWorker | ||
* @package Dusterio\AwsWorker\Wrappers | ||
*/ | ||
class DefaultWorker implements WorkerInterface | ||
{ | ||
/** | ||
* DefaultWorker constructor. | ||
* @param Worker $worker | ||
*/ | ||
public function __construct(Worker $worker) | ||
{ | ||
$this->worker = $worker; | ||
} | ||
|
||
/** | ||
* @param $queue | ||
* @param $job | ||
* @param array $options | ||
* @return void | ||
*/ | ||
public function process($queue, $job, array $options) | ||
{ | ||
$this->worker->process( | ||
$queue, $job, $options['maxTries'], $options['delay'] | ||
); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Dusterio\AwsWorker\Wrappers; | ||
|
||
use Illuminate\Queue\Worker; | ||
use Illuminate\Queue\WorkerOptions; | ||
|
||
/** | ||
* Class Laravel53Worker | ||
* @package Dusterio\AwsWorker\Wrappers | ||
*/ | ||
class Laravel53Worker implements WorkerInterface | ||
{ | ||
/** | ||
* DefaultWorker constructor. | ||
* @param Worker $worker | ||
*/ | ||
public function __construct(Worker $worker) | ||
{ | ||
$this->worker = $worker; | ||
} | ||
|
||
/** | ||
* @param $queue | ||
* @param $job | ||
* @param array $options | ||
* @return void | ||
*/ | ||
public function process($queue, $job, array $options) | ||
{ | ||
$workerOptions = new WorkerOptions($options['delay'], 128, 60, 3, $options['maxTries']); | ||
|
||
$this->worker->process( | ||
$queue, $job, $workerOptions | ||
); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Dusterio\AwsWorker\Wrappers; | ||
|
||
/** | ||
* Interface WorkerInterface | ||
* @package Dusterio\AwsWorker\Wrappers | ||
*/ | ||
interface WorkerInterface | ||
{ | ||
/** | ||
* @param $queue | ||
* @param $job | ||
* @param array $options | ||
* @return mixed | ||
*/ | ||
public function process($queue, $job, array $options); | ||
} |