Created
March 14, 2022 18:10
-
-
Save dgafka/541e2ed1c3f1a1782b490cabb2073a12 to your computer and use it in GitHub Desktop.
scheduling-in-php-07.php
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 | |
#[Asynchronous("invoicing")] | |
class InvoiceGenerator | |
{ | |
#[EventHandler(endpointId: "prepareInvoicing")] | |
public function prepareInvoicing(UserWasRegistered $event, CommandBus $commandBus): void | |
{ | |
echo "User was registered, setting up first invoice generation\n"; | |
$commandBus->send(new GenerateInvoice($event->personId), metadata: ["deliveryDelay" => 3000]); | |
} | |
#[CommandHandler(endpointId: "generateInvoice")] | |
public function generateInvoice(GenerateInvoice $generateInvoice, EventBus $eventBus): void | |
{ | |
echo "Invoice generated for user\n"; | |
$eventBus->publish(new InvoiceWasGenerated($generateInvoice->personId)); | |
} | |
#[EventHandler(endpointId: "generateNextInvoice")] | |
public function generateNextInvoice(InvoiceWasGenerated $event, CommandBus $commandBus): void | |
{ | |
echo "Waiting to generate new invoice\n"; | |
$commandBus->send(new GenerateInvoice($event->personId), metadata: ["deliveryDelay" => 3000]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment