-
Notifications
You must be signed in to change notification settings - Fork 58
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
44 changed files
with
1,880 additions
and
141 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
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,22 @@ | ||
<?php | ||
|
||
namespace think\worker; | ||
|
||
/** | ||
* @mixin \think\worker\conduit\Driver | ||
*/ | ||
class Conduit extends \think\Manager | ||
{ | ||
|
||
protected $namespace = "\\think\\worker\\conduit\\driver\\"; | ||
|
||
protected function resolveConfig(string $name) | ||
{ | ||
return $this->app->config->get("worker.conduit.{$name}", []); | ||
} | ||
|
||
public function getDefaultDriver() | ||
{ | ||
return $this->app->config->get('worker.conduit.type', 'socket'); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace think\worker; | ||
|
||
class Ipc | ||
{ | ||
protected $workerId; | ||
|
||
public function __construct(protected Manager $manager, protected Conduit $conduit) | ||
{ | ||
|
||
} | ||
|
||
public function listenMessage() | ||
{ | ||
$this->subscribe(); | ||
return $this->workerId; | ||
} | ||
|
||
public function sendMessage($workerId, $message) | ||
{ | ||
if ($workerId === $this->workerId) { | ||
$this->manager->triggerEvent('message', $message); | ||
} else { | ||
$this->publish($workerId, $message); | ||
} | ||
} | ||
|
||
public function subscribe() | ||
{ | ||
$this->workerId = $this->conduit->inc('ipc:worker'); | ||
$this->conduit->subscribe("ipc:message:{$this->workerId}", function ($message) { | ||
$this->manager->triggerEvent('message', unserialize($message)); | ||
}); | ||
} | ||
|
||
public function publish($workerId, $message) | ||
{ | ||
$this->conduit->publish("ipc:message:{$workerId}", serialize($message)); | ||
} | ||
} |
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
Oops, something went wrong.