I am currently using redis for message queuing. Because it takes a long time to perform some tasks, a server restart may cause queue consumption to fail.
for example, the process to be performed is as follows:
1. Queue pop-up task
2. Put the task in a zset and judge that the zset, is still there for more than 5 minutes, then join the queue and consume again.
3, consumption task
4, task consumption completed, which is removed from the zset.
what is the problem now? Suppose step 3 lasts for 10 minutes, but zset determines that the queue is dead after more than 5 minutes. So put it back on the mission.
this cycle results in multiple task consumption.
you may want to ask, can"t you just set the time a little longer? It doesn"t matter whether the time is too long or too short, the time is too long, the task waiting time is too long.
and the execution time of each task is uncertain, some 1 minute, some 30 seconds, and 15 minutes in special cases.
forgot to mention that there are dozens of servers in a distributed environment.
I now imagine a solution, and the root of the problem now lies in whether the task is running or not. So I"m thinking about starting here.
so how do you tell if this task is still running? I"m considering maintaining a tasklist queue. Submit to redis every 1 second. At the same time, remove tasks that have not been reported for 5 seconds on a regular basis. When the
task resumes, determine if the task exists in the list.