messenger-monitor-bundle
messenger-monitor-bundle copied to clipboard
document how to set result data
How do I set result data?
My handler
public function __invoke(FetchWikidataMessage $message)
{
$id = $message->getWikidataId();
$wikiData = $this->wikiService->fetchWikidataPage($id);
$official = $this->entityManager->getRepository(Official::class)->findOneBy(['wikidataId' => $id]);
$official->setWikiData($wikiData);
$this->entityManager->flush();;
// set results for the message monitor?
return $wikiData; // nope
// use the logger?
}
You can find the implementation here: https://github.com/zenstruck/messenger-monitor-bundle/blob/1.x/src/History/ResultNormalizer.php
In other words, there are a couple of special handlers, and anything else is handled as a string. Note that if you are returning an object, the recorded data will be null. If you return an array, all scalar values will be used, datetime object converted to a string, and all other stuff to its debug type.
Don't forget to restart the workers after changes!