Bod has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a module to handle Stripe webhook calls. The module does the necessary checking that the call has come from Stripe and provides the user with a means to give defined callbacks for each webhook. They simply pass in a parameter that matches the Stripe event so it is compatible when Stripe adds new events.
The module is instantiated like this:
Here we call &paid; when Stripe sends an invoice.paid event. Plus, we call &all; for every event sent.my $stripe = Stripe::Webhook->new( 'signing_secret' => 'whsec_xxxxxxxxxx', 'invoice-paid' => \&paid, 'all-webhooks' => \&all, );
The person using the module could do things that take a significant time in those subs. But the documentation says "your endpoint must quickly return a successful status code (2xx) prior to any complex logic that could cause a timeout.".
So should I fork to another process for the callback or should I warn the user of the module in the documentation? Something along the lines of: "If your logic might take some time to complete, fork a new process and perform your logic there. This will allow a timely reply to be sent back to Stripe."
Or should I be dealing with this problem in some other way?
This is the code that provides the callback:
my $hook_type = $self->{'webhook'}->{'type'}; $hook_type =~ s/\./-/g; if (defined &{$self->{$hook_type}}) { $self->{'reply'}->{'status'} = 'success'; &{$self->{$hook_type}}($self->{'webhook'}); }
In my own implementation of handling events from Stripe, I only make a couple of calls to the database and write to a text file. But of course, I have no idea what other people might want to do with the callbacks. They might decide to send an email which is usually not exactly quick...
|
|---|