does not rely on the system and does not rely on the Yii transaction mechanism. Human triggering is considered. The trigger can be written on the overall public page, but considering the pressure on the database and WWW server, and the delay problem of the program, some optimization of the execution function is required.
First of all, we consider the pressure on the database. Every time we click on the page, we let it trigger the monitoring system. The monitoring system must first determine whether our task queue needs to be updated at this time (I have stored the task queue in the cache file ), if there is no need to update, you only need to sort the execution queues in the cache file by time, and execute the queues that have timed out. But we need to consider when to update the queue file and how to update it, so as to reduce the pressure on the system.
My idea is, first of all, the cache file may be manually deleted or expired over time, so first check whether the cache file exists each time (generate caches separately by task/user/type), if not, re-query the database , generate cache files (those that have timed out are executed directly, and those that are unsuccessful are thrown into the cache queue).
The next step is for each access. If there is a cache file, first process the timeout task in the file, and then update the cache file. At this time, we encounter a problem, which is the impact on the cache queue during operation. We may need to insert the queue to be executed at the beginning or somewhere in the middle of the cache queue. In this case, we can manually delete the existing queue. The next time it is triggered, because the cache file cannot be found, the latest cache queue will be regenerated.
When we finish executing a task, the entry in the queue will be deleted. If the queue is empty, the query will be re-queried and the queue will be generated, thus ensuring the minimum number of accesses to the database. There is another problem, such as the monitoring of automatic confirmation of receipt of orders. If it is an update to the user's front desk, it is necessary to delete the cache of this user and the cache of the back-end administrator to which the user belongs, so as to ensure that relevant personnel are browsing the order. , all you see is the latest status. In the same way, the backend administrator's modification order should also delete the cache queue of all relevant personnel.