This repository was archived by the owner on Mar 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 389
Supported Swoole async queue driver #136
Merged
albertcht
merged 29 commits into
swooletw:feature/coroutine_feature
from
damonto:feature/swoole_async_task
Sep 2, 2018
Merged
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
208511b
Merge pull request #81 from swooletw/develop
albertcht 51dea74
Merge pull request #84 from swooletw/develop
albertcht 9adb5bf
remove ext-swoole dependency from composer.json becauseof unknown com…
albertcht 32102cf
Merge pull request #87 from swooletw/develop
albertcht 82b0913
fix sandbox enable
albertcht 7e1a9cb
Merge pull request #88 from swooletw/develop
albertcht b30fc40
Update README.md
albertcht 3b816be
fix parser test in swoole 4.0
albertcht e5f1cf7
Merge pull request #91 from swooletw/develop
albertcht b32376c
Update ISSUE_TEMPLATE.md
albertcht d30f44b
Update ISSUE_TEMPLATE.md
albertcht 7c11d75
Update ISSUE_TEMPLATE.md
albertcht 39229ef
Supported Swoole async task queue driver
damonto 0e97d59
Fix AsyncTaskJob not found
damonto 214b619
Remove ServiceProvider
damonto db8ffe2
Fix unable create swoole_server
damonto fc59fa9
fix conflicts
damonto 4034bf3
fix conflicts again
damonto b7249f6
Merged coroutine feature
damonto 83bcd34
Add phpunit test cases
damonto 5783325
Change comments format
damonto 58087d0
Remove getJobExpiration because of unused
damonto 362fbc0
Don't override createObjectPayload
damonto d4656bf
Compatible with older versions
damonto a840966
Fix undefined method getContainer()
damonto 1544615
Move getContainer method to SwooleTaskJob
damonto 6792ed8
Uncomment code
damonto 18c8444
Swoole_timer_after first parameter is microsecond
damonto 7828ef2
Merge branch 'feature/coroutine_feature' into feature/swoole_async_task
albertcht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| <?php | ||
|
|
||
| namespace SwooleTW\Http\Task\Connectors; | ||
|
|
||
| use SwooleTW\Http\Task\SwooleTaskQueue; | ||
| use Illuminate\Queue\Connectors\ConnectorInterface; | ||
|
|
||
| class SwooleTaskConnector implements ConnectorInterface | ||
| { | ||
| /** | ||
| * Swoole Server Instance | ||
| * | ||
| * @var \Swoole\Http\Server | ||
| */ | ||
| protected $swoole; | ||
|
|
||
| /** | ||
| * Create a new Swoole Async task connector instance. | ||
| * | ||
| * @param \Swoole\Http\Server $swoole | ||
| * @return void | ||
| */ | ||
| public function __construct($swoole) | ||
| { | ||
| $this->swoole = $swoole; | ||
| } | ||
|
|
||
| /** | ||
| * Establish a queue connection. | ||
| * | ||
| * @param array $config | ||
| * @return \Illuminate\Contracts\Queue\Queue | ||
| */ | ||
| public function connect(array $config) | ||
| { | ||
| return new SwooleTaskQueue($this->swoole); | ||
| } | ||
| } |
This file contains hidden or 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,83 @@ | ||
| <?php | ||
|
|
||
| namespace SwooleTW\Http\Task; | ||
|
|
||
| use Illuminate\Queue\Jobs\Job; | ||
| use Illuminate\Contracts\Container\Container; | ||
| use Illuminate\Contracts\Queue\Job as JobContract; | ||
|
|
||
| class SwooleTaskJob extends Job implements JobContract | ||
| { | ||
| /** | ||
| * The Swoole Server instance. | ||
| * | ||
| * @var \Swoole\Http\Server | ||
| */ | ||
| protected $swoole; | ||
|
|
||
| /** | ||
| * The Swoole async job raw payload. | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $job; | ||
|
|
||
| /** | ||
| * The Task id | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $taskId; | ||
|
|
||
| /** | ||
| * The src worker Id | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $srcWrokerId; | ||
|
|
||
| /** | ||
| * Create a new job instance. | ||
| * | ||
| * @param \Illuminate\Container\Container $container | ||
| * @param \Swoole\Http\Server $swoole | ||
| * @param string $job | ||
| * @return void | ||
| */ | ||
| public function __construct(Container $container, $swoole, $job, $taskId, $srcWrokerId) | ||
| { | ||
| $this->container = $container; | ||
| $this->swoole = $swoole; | ||
| $this->job = $job; | ||
| $this->taskId = $taskId; | ||
| $this->srcWorkderId = $srcWrokerId; | ||
| } | ||
|
|
||
| /** | ||
| * Get the number of times the job has been attempted. | ||
| * @return int | ||
| */ | ||
| public function attempts() | ||
| { | ||
| return ($this->job['attempts'] ?? null) + 1; | ||
| } | ||
|
|
||
| /** | ||
| * Get the raw body string for the job. | ||
| * @return string | ||
| */ | ||
| public function getRawBody() | ||
| { | ||
| return $this->job; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Get the job identifier. | ||
| * @return string | ||
| */ | ||
| public function getJobId() | ||
| { | ||
| return $this->taskId; | ||
| } | ||
| } |
This file contains hidden or 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,105 @@ | ||
| <?php | ||
|
|
||
| namespace SwooleTW\Http\Task; | ||
|
|
||
| use Exception; | ||
| use Illuminate\Queue\Queue; | ||
| use Illuminate\Contracts\Queue\Queue as QueueContract; | ||
|
|
||
| class SwooleTaskQueue extends Queue implements QueueContract | ||
| { | ||
| /** | ||
| * Swoole Connector | ||
| * | ||
| * @var \Swoole\Http\Server | ||
| */ | ||
| protected $swoole; | ||
|
|
||
| /** | ||
| * Create Async Task instance. | ||
| * | ||
| * @param \Swoole\Http\Server $swoole | ||
| */ | ||
| public function __construct($swoole) | ||
| { | ||
| $this->swoole = $swoole; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Push a new job onto the queue. | ||
| * | ||
| * @param string|object $job | ||
| * @param mixed $data | ||
| * @param string $queue | ||
| * @return mixed | ||
| */ | ||
| public function push($job, $data = '', $queue = null) | ||
| { | ||
| return $this->pushRaw($this->createPayload($job, $data), $queue); | ||
| } | ||
|
|
||
| /** | ||
| * Push a raw payload onto the queue. | ||
| * | ||
| * @param string $payload | ||
| * @param string $queue | ||
| * @param array $options | ||
| * @return mixed | ||
| */ | ||
| public function pushRaw($payload, $queue = null, array $options = []) | ||
| { | ||
| return $this->swoole->task($payload, ! is_numeric($queue) ? 1 : (int) $queue); | ||
| } | ||
|
|
||
| /** | ||
| * Push a new job onto the queue after a delay. | ||
| * | ||
| * @param \DateTimeInterface|\DateInterval|int $delay | ||
| * @param string|object $job | ||
| * @param mixed $data | ||
| * @param string $queue | ||
| * @return mixed | ||
| */ | ||
| public function later($delay, $job, $data = '', $queue = null) | ||
| { | ||
| return swoole_timer_after($this->secondsUntil($delay), function () use ($job, $data, $queue) { | ||
| return $this->push($job, $data, $queue); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Create a typical, string based queue payload array. | ||
| * | ||
| * @param string $job | ||
| * @param mixed $data | ||
| * | ||
| * @throws Expcetion | ||
| */ | ||
| protected function createStringPayload($job, $data) | ||
| { | ||
| throw new Exception("Unsupported empty data"); | ||
| } | ||
|
|
||
| /** | ||
| * Get the size of the queue. | ||
| * | ||
| * @param string $queue | ||
| * @return int | ||
| */ | ||
| public function size($queue = null) | ||
| { | ||
| return -1; | ||
| } | ||
|
|
||
| /** | ||
| * Pop the next job off of the queue. | ||
| * | ||
| * @param string $queue | ||
| * @return \Illuminate\Contracts\Queue\Job|null | ||
| */ | ||
| public function pop($queue = null) | ||
| { | ||
| return null; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.