-1

Have a basic requirement, whereby after the user submits product/other details on checkout and they are sent to the server, the order is processed/created and I then need to send a bunch of emails.

I want the server to respond/return to the client that the order has been successfully placed immediately after the order and payment has been processed, but the email sending job will continue on the server without having to return anything to the client.

Would my best bet be to use the Laravel Task Scheduler via kernel.php and have it check for updates to orders table on a minute by minute basis and if new orders detected send those emails out.

Or can I skip the Task Scheduler altogether and simply return a status 200, success response to the client, but have the code continue executing on the server, sending those Emails out ?

I am also on basic shared/cpanel hosting, so not sure if I can run some artisan queue listeners etc.

LaserBeak
  • 3,257
  • 10
  • 43
  • 73

2 Answers2

0

You might want to look into Event and Queue, with Events you could easily queue something to be executed in the background when something happens.

In the Laravel documentation, it's quite similar to what you want to do I presume.

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
  'App\Events\PodcastWasPurchased' => [
    'App\Listeners\EmailPurchaseConfirmation',
],
];
SteD
  • 13,909
  • 12
  • 65
  • 76
  • But will I then need something to trigger the queue to execute, which brings me back to having to use task scheduler or can I say create a queued item and specify that it should be executed in say 10 seconds and deleted after ? I am on shared hosting, so I don't think I can ran some lower level queue listener processes – LaserBeak Jun 24 '16 at 04:56
0

As you are in shared hosting, you may not be able to run any type of queue processing system like supervisord or redis. But, you can use Amazon SQS to handle your queue.

In another way, you can save what email to send to which address in your database when a order is happened and return a 200 status code to the client. Later on, run task scheduler every 5 mins to send those email and if successful, delete that row from db. It'll reduce load on db to search over all orders to find the new one.

Sovon
  • 1,804
  • 1
  • 22
  • 30