![]() |
Hi,
I'm looking for advice on best practice to processing webhook data after returning 202 success to the webhook? As there is only a short window for responding to the webhook (5 secs) and potentially a lot of heavy work to do processing the webhook data, I need to call a class or method in the controller AFTER responding to the webhook Code: return $this->response->setStatusCode(200); Should this be done with a "post_system" Event (can I pass the webhook payload data to the event from the controller? can I restrict the event to being called only after a specific Controller has finished running?), or is there an alternative? I would be grateful if someone could point me in the right direction? Many Thanks
what i do in a similar situation is save the data to a pending table and use a cron job to check the table every minute or so
Thanks badger,
I've considered using CRON, but as I need to process the webhook data immediately, therefore I can't really wait for the CRON to run. Also, when considering CRON this it seemed like running the CRON very minute or so, then writing, reading, updating/removing data from the database was significant waste of resources. Therefore I was hoping to use the Codeigniter Events functionality, or something similar, to run only after webhook controller was called, as this would seem to make more sense. But, it seems Codeigniter doesn't support this type of processing! Thanks again :-)
After considerable web searching using Stack Overflow in conjunction with the CI manual, I was able to to establish I need to apply a filter NOT event.
First I set up my filter. NOTE: as I only want the filter to apply AFTER the controller has run, i.e. after the controller has responded to the 3rd party webhook in a timely manner, I only need to define the after function. PHP Code: <?php namespace App\Libraries\Filters; PHP Code: public $aliases = [ Then, as I only want the filter to apply to a single controller and I don't want to list (and keep updating) all excluded controllers. I applied my alias to a url filter, NOT global. , Note: my before and after url pattern is an exact match to the controller I want this filter to be applied to (not sure if this is a proper usage, but it works!!) as I do not want it to be applied anywhere else. PHP Code: public $filters = [ Many thanks, I believe I have found a solution without the resource overhead of CRONs and database queries |
Welcome Guest, Not a member yet? Register Sign In |