Created
August 1, 2022 05:14
-
-
Save wazum/a5616857d1c4a97be8d58fc79d3f98d8 to your computer and use it in GitHub Desktop.
Symfony Batch Handler example
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
<?php | |
… | |
class MyBatchHandler implements BatchHandlerInterface | |
{ | |
use BatchHandlerTrait; | |
public function __invoke(MyMessage $message, Acknowledger $ack = null) | |
{ | |
return $this->handle($message, $ack); | |
} | |
private function process(array $jobs): void | |
{ | |
foreach ($jobs as [$message, $ack]) { | |
try { | |
// [...] compute $result from $message | |
$ack->ack($result); | |
} catch (\Throwable $e) { | |
$ack->nack($e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment