Scheduled a certain time

Hi everyone,
I need to create a task that runs at a certain time to cancel an order from the adatbase 30 minutes after the creation date.
I could use scheduled actions but that would mean running the script every minute even if there are no records to delete.
Do you have any ideas?

you can use the Action Scheduler from the browser side thats in the components folder? Just set it to run every 30 minutes?

The problem with using the scheduler on the front end is that you will have to have the page open in a browser at all times for it to run.

If you are running a Node.js project you have access to the server side scheduler. I haven’t used it but I believe that is what you are looking for.

Or a cron job */30 * * * * api\.....

I’m using the server side NodeJS scheduler and its been bombroof reliable so far (after a few months). I’m beginning to really trust it, it’s great.

1 Like

Thanks everyone for the replies.
I already use server-side scheduled events in NODE JS and they work pretty well.
In this case I would need to do something slightly different, i.e. launch a task at a defined time, for example if a user opts for a service at 10:12 am the same option should be canceled at 10:42 am if converted into an order.
Probably the only option I have using scheduled events is to launch an action every 30 minutes that checks options that have been running for more than 30 minutes.

1 Like

That would depend on how accurate you need the time cancellation to be? If you don’t need accuracy then your suggestion is great, if you need to have it cancel after exactly 30 minutes though you will probably need to run the scheduler every minute. If its a simple query like a boolean change to the status then server overheard would be almost invisible.

I do something similar but this is done directly in the DB using an event chedule:

https://medium.com/@sumitkum001/demystifying-mysql-unveiling-the-magic-of-event-scheduling-aa4581ab8911#:~:text=Event%20scheduling%20is%20a%20powerful,scheduling%20can%20streamline%20these%20processes.

I normally set it up with HeidiSQL but you can also write it yourself in a simple statement, looks like this:

CREATE DEFINER=`YOURDBNAME`@`%` EVENT `RANDOM_NAMEOF_YOUREVENT`
	ON SCHEDULE
		EVERY 1 MINUTE STARTS '2024-04-11 19:48:25' ENDS '2099-04-11 13:57:25'
	ON COMPLETION PRESERVE
	ENABLE
	COMMENT 'NOTES FOR YOUR OWN USE HERE'
	DO BEGIN
DELETE from YOURTABLE WHERE TIMEORDERED ='0000-00-00 00:00:00'; <====yOUR sql STATEMENT GOES HERE
END
1 Like

Running every minute is considered industry-standard. If you want to maximize performance you can index relevant columns on your database

2 Likes