Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding UUID accessor method #63

Merged
merged 1 commit into from
Oct 4, 2020
Merged

Conversation

claudsonm
Copy link
Contributor

@claudsonm claudsonm commented Oct 4, 2020

One thing that I miss about this package is the ability to get the UUID property of the job being dispatched, and decided to implement this during Hacktoberfest.

Why this is useful

In my projects, every critical communication that our servers establish with others have to be logged on Elasticsearch. It's important to be able to track things, and UUIDs are excellent for that. By default, when we call WebhookCall::create() it will use the default values from the configuration, except for one: the UUID, which is defined in that moment.

To be able to persist and "associate" the job dispatched with the document on Elasticsearch, we are overriding the UUID property, just because we do not have access to the default value created by the package. It is a minor improvement, but one less overhead.

// Before
$webhookCall = WebhookCall::create()
            ->uuid($myIdentification = Str::uuid())
           ->payload($body)
            ->dispatch();

$document = [
            'index' => 'webhooks_dispatched',
            'id' => $myIdentification,
            'body' => $body,
        ];

// After
$webhookCall = WebhookCall::create()
           ->payload($body)
            ->dispatch();

$document = [
            'index' => 'webhooks_dispatched',
            'id' => $webhookCall->getUuid(),
            'body' => $body,
        ];

@freekmurze freekmurze merged commit d2efcf7 into spatie:master Oct 4, 2020
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants