Skip to content

Commit

Permalink
add comments for process pool
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 13, 2020
1 parent 852e75f commit 29977fa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/process/src/Annotation/Mapping/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class Process
{
/**
* Default
* Default run the first worker
*/
public const DEFAULT = -1;

Expand Down
3 changes: 2 additions & 1 deletion src/process/src/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function beans(): array
'on' => [
SwooleEvent::WORKER_START => bean(WorkerStartListener::class),
SwooleEvent::WORKER_STOP => bean(WorkerStopListener::class)
]
],
'workerNum' => 2,
]
];
}
Expand Down
27 changes: 27 additions & 0 deletions src/process/src/Contract/MessageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://swoft.org/docs
* @contact [email protected]
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/

namespace Swoft\Process\Contract;

use Swoole\Process\Pool;

/**
* Class MessageInterface
*
* @since 2.0
*/
interface MessageInterface
{
/**
* @param Pool $pool
* @param string $data
*/
public function onMessage(Pool $pool, string $data): void;
}
2 changes: 1 addition & 1 deletion src/process/src/ProcessDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function dispatcher(Pool $pool, int $workerId): void
private function getProcess(int $workerId): ProcessInterface
{
$processName = ProcessRegister::getProcess($workerId);
$process = BeanFactory::getBean($processName);

$process = BeanFactory::getBean($processName);
if (!$process instanceof ProcessInterface) {
throw new ProcessException('Process must be instanceof ProcessInterface');
}
Expand Down
9 changes: 8 additions & 1 deletion src/process/src/SwooleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Swoft\Process\Contract\WorkerStartInterface;
use Swoft\Process\Contract\WorkerStopInterface;
use Swoft\Process\Contract\MessageInterface;

/**
* Class SwooleEvent
Expand All @@ -30,11 +31,17 @@ class SwooleEvent
*/
public const WORKER_STOP = 'workerStop';

/**
* On message
*/
public const MESSAGE = 'message';

/**
* Listener mapping
*/
public const LISTENER_MAPPING = [
self::WORKER_START => WorkerStartInterface::class,
self::WORKER_STOP => WorkerStopInterface::class
self::WORKER_STOP => WorkerStopInterface::class,
self::MESSAGE => MessageInterface::class
];
}

0 comments on commit 29977fa

Please sign in to comment.