Requirements/scenarios:
For example, set an article to be published on 2018-5-22 13:51:16.
Notify me in three days.
Messages are automatically deleted after expiration.
……
Waiting for this kind of demand, it is to do something automatically at a certain point in time. This seems to have nothing to do with the queue. Does it require some middleware or other time, or a resident process or something.
My understanding is that the tasks to be done are placed in a table row by row, and then a process is continuously refreshed. The tasks that meet the time node are taken out for execution. Is this the idea?
Want to know what the mature solution for this scenario is made of?
Thank you^_^
仅有的幸福2017-05-24 11:35:02
Use delayed tasks, https://github.com/ouqiang/go...
Implement it yourself, use time wheel or small root pile
Use redis keyspace notification
beanstalkd
曾经蜡笔没有小新2017-05-24 11:35:02
The main thing of the poster should be DelayQueue, which is the delayed message queue service. For specific scenarios, please refer to:
1. Taobao’s automatic order cancellation service
2. Ele.me’s order SMS notification service, etc.
Implement Timer based on wait/notify method.
伊谢尔伦2017-05-24 11:35:02
You can use crontab scheduled tasks to solve it, and you can design the Php interface to be called every day, hour, and minute.
習慣沉默2017-05-24 11:35:02
Program brushing, but database pressure must be considered.
You can push all tasks into the queue, take the script out of the queue in an infinite loop, compare the time points, and throw the tasks to the execution module when it arrives. If the time is not up, continue to the other side and push into the queue.
Two queues. For example, queue to be executed: tasteList; queue to be executed immediately: runList.
Divide task retrieval and task execution into different processes:
1. Task retrieval: The script pops tasks from tasteList in a loop, determines the time point, and pushes the task to the runList queue when the time is up. If it is not enough, continue to push it into the tasteList;
2. Execute the task: loop through the runList to pop, and execute it as soon as there is a task.
When the volume is large, you can just open a few processes as needed, and there is no need to think about repeating the execution.
phpcn_u15822017-05-24 11:35:02
Just use the system’s scheduled task function to trigger a script. You can decide what the script does and how to do it. You can also refer to the answer above.
Generally speaking, a high-frequency script is enough (for example, once a minute or once every 5 minutes). You can judge the time within the script and then call tasks with different frequencies. This is much easier to manage than setting up scheduled tasks for each frequency script separately. .
怪我咯2017-05-24 11:35:02
That is, you save the data and then make a script to continuously detect it. . For example, test once every 1 minute