-
-
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,722 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,52 @@ | ||
<?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 $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); | ||
} | ||
|
||
private function process(array $jobs): void | ||
Check failure on line 41 in src/AsyncHandler/BatchAsyncHandler.php GitHub Actions / Execute PHPStan analysis (8.3)
|
||
{ | ||
foreach ($jobs as [$event, $ack]) { | ||
$ack->ack($event); | ||
} | ||
} | ||
|
||
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
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.