Describe your problem
Recently development encountered a large number of orders expired processing problems, such as I took a product, half an hour after he could not pay or the order should be deleted.
First, the reaction is crontab, but considering every time to check MySQL, feeling will affect the efficiency;
Second, I was prompted to use the message queue RABBITMQ, but I saw a half-day feeling that the message queue seems to be useless, I feel logic or when the order is taken to send a message, and then the PHP process has been in that sleep? It is estimated that I do not understand enough to ask God to explain the relevant process.
Thirdly, is there any other way? The great God gives a specific point of the plan to scatter ~
Paste the relevant code
Post error message
Paste the relevant
What methods have been tried still unresolved (attached link)
Reply content:
Describe your problem
Recently development encountered a large number of orders expired processing problems, such as I took a product, half an hour after he could not pay or the order should be deleted.
First, the reaction is crontab, but considering every time to check MySQL, feeling will affect the efficiency;
Second, I was prompted to use the message queue RABBITMQ, but I saw a half-day feeling that the message queue seems to be useless, I feel logic or when the order is taken to send a message, and then the PHP process has been in that sleep? It is estimated that I do not understand enough to ask God to explain the relevant process.
Thirdly, is there any other way? The great God gives a specific point of the plan to scatter ~
Paste the relevant code
Post error message
Paste the relevant
What methods have been tried still unresolved (attached link)
Low cost solution
Insert an expiration time when inserting an order
And then the server is constantly querying the MySQL database with CLI mode.
Indexing MySQL expiration time does not affect efficiency
If there is a need for operational costs, it can be achieved through user-triggered mode:
Set the "Expiration Time" datetime when the product is finished.
The user updates the "Expiration Time" at the same time for any updates to the item.
Each time the user logs in, read the relevant products by PHP compared to the current time (if the time is strict, it is recommended to use JS comparison time) and the product expiration time. If it expires, you can use CSS to identify that the current product has expired. The colleague sends the request to the RABBITMQ queue because the product ID has been obtained when the product is read, so the best queue information is to include this ID.
The background has crontab timed to read rabbitmq and batch deleted MySQL statements based on a known ID.
This processing method can save resources, reduce unnecessary consumption of services, basically is a read, a delete database operations. It is not recommended to delete the article by item, it is also recommended to search MySQL to find outdated entries, preferably according to RABBITMQ queue production batch DELETE statements.
You can put an order in Redis to set the expiration time for Redis
The Expiration time index, and then the scheduled task to process, each update fixed bar number is good. For example, the timing of the script every start, according to the criteria to query, each check 1000, update status for overdue unpaid, if the results of less than 1000 or no results, it does not need to check the next time.
Your question is not to shoot after half an hour without payment on the deletion, if so, the following points of thinking you can see
。
NoSQL, which needs to be persistent, uses Redis to set the expiration time and automatically delete it after the time (this is the case for NoSQL features), and your foreground program needs to be judged.
2. If Redis is not allowed (that is, with MySQL-type relational database), but also the time to set the expiration time stamp, and then on the order-related pages manually whether to expire (if the Expiration time and order in a table, will not waste resources ah, take more than one field)
Is my understanding wrong, why need crontab and message queue??