I'm trying to implement a functionality where a user gets a communication exactly after 10 minutes after hi placed an order. How to accomplish this in magento 2?
I don't think this is possible using only Magento out of the box functionalities. To solve a similar situation I have implemented a Console Application using C# and the addComment Webservice. Then I set it up as a Windows service hat runs every hour to check if there is an order that needs to be acted upon.
Here is the webservice you can use to do that "/rest/V1/orders/orderId/comments".
You can also do this in a php script and set it up to run on your server every 10 minutes.
Create a simple module with an observer for the
checkout_submit_all_after event that writes the order data including a timestamp to a file in a cache folder. Then use a cron job to process the files in that folder looking at the timestamp and creating the email if the timestamp is older than 10mins.
Break this process into a two-step
use an appropriate observer to create a log (custom table and also add email send flag) for order.
Create a cron job to check order timestamp (created date) using current time minus 10 minutes whichever is small than that time with email not send a flag to send email to them.
Other than that if you want to run some js function after an order place in a time span of 10 minutes then you can create cookies on the order success page to store timestamp and then if cookies there use time interval and check if the time difference is or more than 10 min. if yes delete that cookie and stop the time interval function and call your function.
Note: keep that checking cookie js on all pages and with proper implementation of code
Normally I would mention to queue this by native functionality (https://devdocs.magento.com/guides/v2.4/config-guide/mq/manage-message-queues.html), but with a delay of 10 minutes this is probably not the way to go natively. I still would say some form of queuing is probably the nicest approach to do this.
But it is easier to create an extra column (with an index!) in sales_order or a separate table with a flag for if this specific event is fired or not. Then you can add a cronjob that will just traverse a collection that has the flag set to 0 and is filtering on order entities that are older then 10 minutes. You can then fire your event/action.