-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Built out initial worker pool/supervisor, auto scale system, and alerts - Setup repo, tests, docs - Enabled auto scale debouncing Signed-off-by: RJ Garcia <[email protected]>
- Loading branch information
Showing
74 changed files
with
2,949 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor | ||
/composer.lock | ||
/var/ | ||
/tests/Feature/Fixtures/_message-info.txt |
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,8 @@ | ||
FROM php:7.2-cli | ||
|
||
RUN apt-get update && apt-get install -y git zip | ||
|
||
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/ | ||
RUN install-php-extensions redis pcntl | ||
|
||
COPY --from=composer:1.9.1 /usr/bin/composer /usr/bin/composer |
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 RJ Garcia | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,47 @@ | ||
{ | ||
"name": "krak/symfony-messenger-auto-scale", | ||
"description": "Symfony Messenger Auto Scaling", | ||
"type": "symfony-bundle", | ||
"authors": [ | ||
{ | ||
"name": "RJ Garcia", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.1", | ||
"ext-pcntl": "*", | ||
"krak/schema": "^0.2.0", | ||
"psr/event-dispatcher": "^1.0", | ||
"symfony/messenger": "^4.4" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Krak\\SymfonyMessengerAutoScale\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Krak\\SymfonyMessengerAutoScale\\Tests\\": "tests" | ||
} | ||
}, | ||
"require-dev": { | ||
"ext-redis": "*", | ||
"krak/symfony-messenger-redis": "^0.1.0", | ||
"nyholm/symfony-bundle-test": "^1.6", | ||
"phpunit/phpunit": "^7.3", | ||
"psr/simple-cache": "^1.0", | ||
"symfony/cache": "^5.0", | ||
"symfony/console": "^4.4", | ||
"symfony/dependency-injection": "^4.1", | ||
"symfony/http-kernel": "^4.1", | ||
"symfony/process": "^5.0", | ||
"symfony/property-access": "^4.1", | ||
"symfony/serializer": "^4.1" | ||
}, | ||
"scripts": { | ||
"test": "phpunit --testdox --colors=always", | ||
"flush-redis": "docker-compose exec -T redis redis-cli flushall" | ||
} | ||
} |
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,14 @@ | ||
version: '3' | ||
|
||
services: | ||
php: | ||
build: . | ||
command: "tail -f /dev/null" | ||
working_dir: /var/www/html | ||
volumes: | ||
- ./:/var/www/html | ||
redis: | ||
image: redis | ||
environment: { TERM: xterm } | ||
ports: ["6379:6379"] | ||
restart: unless-stopped |
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php"> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
<env name="SHELL_VERBOSITY" value="-1" /> | ||
<env name="REDIS_DSN" value="redis://localhost:6379?queue=messenger"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="feature"> | ||
<directory>tests/Feature</directory> | ||
</testsuite> | ||
<testsuite name="unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,29 @@ | ||
<?php | ||
|
||
namespace Krak\SymfonyMessengerAutoScale; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface; | ||
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; | ||
|
||
/** take a collection of receivers and return the total count of pending messages */ | ||
final class AggregatingReceiverMessageCount implements MessageCountAwareInterface | ||
{ | ||
private $receivers; | ||
|
||
public function __construct(ReceiverInterface ...$receivers) { | ||
$this->receivers = $receivers; | ||
} | ||
|
||
public static function createFromReceiverIds(array $receiverIds, ContainerInterface $receiversById) { | ||
return new self(...array_map(function(string $receverId) use ($receiversById) { | ||
return $receiversById->get($receverId); | ||
}, $receiverIds)); | ||
} | ||
|
||
public function getMessageCount(): int { | ||
return array_reduce($this->receivers, function(int $sum, ReceiverInterface $receiver) { | ||
return $receiver instanceof MessageCountAwareInterface ? $receiver->getMessageCount() + $sum : $sum; | ||
}, 0); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace Krak\SymfonyMessengerAutoScale; | ||
|
||
use Krak\SymfonyMessengerAutoScale\AutoScale\AutoScaleRequest; | ||
use Krak\SymfonyMessengerAutoScale\AutoScale\AutoScaleResponse; | ||
|
||
/** Service responsible for determining the appropriate size of the pool based off of current state of pool and config */ | ||
interface AutoScale | ||
{ | ||
public function __invoke(AutoScaleRequest $req): AutoScaleResponse; | ||
} |
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 Krak\SymfonyMessengerAutoScale\AutoScale; | ||
|
||
use Krak\SymfonyMessengerAutoScale\PoolConfig; | ||
|
||
final class AutoScaleRequest | ||
{ | ||
private $state; | ||
private $timeSinceLastCall; | ||
private $numProcs; | ||
private $sizeOfQueue; | ||
private $poolConfig; | ||
|
||
public function __construct(?array $state, ?int $timeSinceLastCall, int $numProcs, int $sizeOfQueue, PoolConfig $poolConfig) { | ||
$this->state = $state; | ||
$this->timeSinceLastCall = $timeSinceLastCall; | ||
$this->numProcs = $numProcs; | ||
$this->sizeOfQueue = $sizeOfQueue; | ||
$this->poolConfig = $poolConfig; | ||
} | ||
|
||
public function state(): ?array { | ||
return $this->state; | ||
} | ||
|
||
public function timeSinceLastCall(): ?int { | ||
return $this->timeSinceLastCall; | ||
} | ||
|
||
public function numProcs(): int { | ||
return $this->numProcs; | ||
} | ||
|
||
public function sizeOfQueue(): int { | ||
return $this->sizeOfQueue; | ||
} | ||
|
||
public function poolConfig(): PoolConfig { | ||
return $this->poolConfig; | ||
} | ||
} |
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 Krak\SymfonyMessengerAutoScale\AutoScale; | ||
|
||
final class AutoScaleResponse | ||
{ | ||
private $state; | ||
private $expectedNumProcs; | ||
|
||
public function __construct(?array $state, int $expectedNumProcs) { | ||
if ($expectedNumProcs < 0) { | ||
throw new \RuntimeException('Expected number of procs must be zero or greater.'); | ||
} | ||
$this->state = $state; | ||
$this->expectedNumProcs = $expectedNumProcs; | ||
} | ||
|
||
public function state(): ?array { | ||
return $this->state; | ||
} | ||
|
||
public function withState(?array $state): self { | ||
$self = clone $this; | ||
$self->state = $state; | ||
return $self; | ||
} | ||
|
||
public function withAddedState(array $stateToMerge): self { | ||
return $this->withState(array_merge($this->state ?? [], $stateToMerge)); | ||
} | ||
|
||
public function expectedNumProcs(): int { | ||
return $this->expectedNumProcs; | ||
} | ||
|
||
public function withExpectedNumProcs(int $expectedNumProcs): self { | ||
$self = clone $this; | ||
$self->expectedNumProcs = $expectedNumProcs; | ||
return $self; | ||
} | ||
} |
Oops, something went wrong.