Skip to content

Instantly share code, notes, and snippets.

@wazum
Created August 1, 2022 05:14
Show Gist options
  • Save wazum/a5616857d1c4a97be8d58fc79d3f98d8 to your computer and use it in GitHub Desktop.
Save wazum/a5616857d1c4a97be8d58fc79d3f98d8 to your computer and use it in GitHub Desktop.
Symfony Batch Handler example
<?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