background
Recently there is a business, roughly as follows:
Problem : The platform does not know when the customer will complete the contract. Currently, timed tasks are used for polling every few minutes, but if every time a timed task is executed, it will be a waste of resources to query the capital. Because after the customer initiated the contract, the contract may not have been signed.
Simple solution
- Through redis, record the query count queryCount, the query failure count errorCount, the failure count order and errorCountSum of each customer's contract result through redis (I wanted to use the N-th power method of 2 to compare this exponential growth too fast).
- Check whether the current query count queryCount is greater than the sum of the number of failures and errorCountSum. If it is greater than it is executed, otherwise the query capital logic is not executed.
- The effect of failures n times and n times of timing tasks without querying the capital is realized.
- Of course, when the customer re-initiates the contract, the count will be re-counted.