Timed task failure retry time extension record

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

  1. 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).
  2. 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.
  3. The effect of failures n times and n times of timing tasks without querying the capital is realized.
  4. Of course, when the customer re-initiates the contract, the count will be re-counted.

Guess you like

Origin blog.csdn.net/H_Rhui/article/details/108507348