-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
29 changed files
with
2,738 additions
and
1,752 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\AsyncHandler; | ||
|
||
use Flow\AsyncHandlerInterface; | ||
use Flow\Event; | ||
use Flow\Event\AsyncEvent; | ||
|
||
use function call_user_func_array; | ||
|
||
final class AsyncHandler implements AsyncHandlerInterface | ||
{ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
Event::ASYNC => 'async', | ||
]; | ||
} | ||
|
||
public function async(AsyncEvent $event): void | ||
{ | ||
$event->setReturn(call_user_func_array($event->getAsync(), $event->getArgs())); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\AsyncHandler; | ||
|
||
use Flow\AsyncHandlerInterface; | ||
use Flow\Event; | ||
use Flow\Event\AsyncEvent; | ||
use Symfony\Component\Messenger\Handler\Acknowledger; | ||
use Symfony\Component\Messenger\Handler\BatchHandlerInterface; | ||
use Symfony\Component\Messenger\Handler\BatchHandlerTrait; | ||
use Throwable; | ||
|
||
use function call_user_func_array; | ||
|
||
final class BatchAsyncHandler implements BatchHandlerInterface, AsyncHandlerInterface | ||
{ | ||
use BatchHandlerTrait; | ||
|
||
public function __construct( | ||
private int $batchSize = 10, | ||
) {} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
Event::ASYNC => 'async', | ||
]; | ||
} | ||
|
||
public function async(AsyncEvent $event): void | ||
{ | ||
$ack = new Acknowledger(get_debug_type($this), static function (?Throwable $e = null, $event = null) { | ||
$event->setReturn(call_user_func_array($event->getAsync(), $event->getArgs())); | ||
}); | ||
|
||
$this->handle($event, $ack); | ||
} | ||
|
||
/** | ||
* PHPStan should normaly pass for method.unused | ||
* https://github.com/phpstan/phpstan/issues/6039 | ||
* https://phpstan.org/r/8f7de023-9888-4dcb-b12c-e2fcf9547b6c. | ||
* | ||
* @param array{0: AsyncEvent, 1: Acknowledger}[] $jobs | ||
* | ||
* @phpstan-ignore method.unused | ||
*/ | ||
private function process(array $jobs): void | ||
{ | ||
foreach ($jobs as [$event, $ack]) { | ||
$ack->ack($event); | ||
} | ||
} | ||
|
||
/** | ||
* PHPStan should normaly pass for method.unused | ||
* https://github.com/phpstan/phpstan/issues/6039 | ||
* https://phpstan.org/r/8f7de023-9888-4dcb-b12c-e2fcf9547b6c. | ||
* | ||
* @phpstan-ignore method.unused | ||
*/ | ||
private function getBatchSize(): int | ||
{ | ||
return $this->batchSize; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
interface AsyncHandlerInterface extends EventSubscriberInterface {} |
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
Oops, something went wrong.