Commit b93f3d18c049ff9c83a0278e975f5ba018948dfc
1 parent
8ec23f22
added ability to use exp-pause-between-retries on queue msgs reprocessing
Showing
3 changed files
with
40 additions
and
4 deletions
... | ... | @@ -27,6 +27,7 @@ import java.util.UUID; |
27 | 27 | import java.util.concurrent.ConcurrentHashMap; |
28 | 28 | import java.util.concurrent.ConcurrentMap; |
29 | 29 | import java.util.concurrent.TimeUnit; |
30 | +import java.util.concurrent.atomic.AtomicInteger; | |
30 | 31 | |
31 | 32 | @Component |
32 | 33 | @Slf4j |
... | ... | @@ -58,6 +59,12 @@ public class TbRuleEngineProcessingStrategyFactory { |
58 | 59 | private final double maxAllowedFailurePercentage; |
59 | 60 | private final long pauseBetweenRetries; |
60 | 61 | |
62 | + private final boolean expPauseBetweenRetries; | |
63 | + | |
64 | + private long maxExpPauseBetweenRetries; | |
65 | + private int maxExpDegreeValue; | |
66 | + private AtomicInteger expDegreeStep; | |
67 | + | |
61 | 68 | private int initialTotalCount; |
62 | 69 | private int retryCount; |
63 | 70 | |
... | ... | @@ -69,6 +76,12 @@ public class TbRuleEngineProcessingStrategyFactory { |
69 | 76 | this.maxRetries = configuration.getRetries(); |
70 | 77 | this.maxAllowedFailurePercentage = configuration.getFailurePercentage(); |
71 | 78 | this.pauseBetweenRetries = configuration.getPauseBetweenRetries(); |
79 | + this.expPauseBetweenRetries = configuration.isExpPauseBetweenRetries(); | |
80 | + if (this.expPauseBetweenRetries) { | |
81 | + this.expDegreeStep = new AtomicInteger(1); | |
82 | + this.maxExpPauseBetweenRetries = configuration.getMaxExpPauseBetweenRetries(); | |
83 | + this.maxExpDegreeValue = new Double(Math.log(maxExpPauseBetweenRetries) / Math.log(pauseBetweenRetries)).intValue(); | |
84 | + } | |
72 | 85 | } |
73 | 86 | |
74 | 87 | @Override |
... | ... | @@ -103,10 +116,25 @@ public class TbRuleEngineProcessingStrategyFactory { |
103 | 116 | toReprocess.forEach((id, msg) -> log.trace("Going to reprocess [{}]: {}", id, TbMsg.fromBytes(result.getQueueName(), msg.getValue().getTbMsg().toByteArray(), TbMsgCallback.EMPTY))); |
104 | 117 | } |
105 | 118 | if (pauseBetweenRetries > 0) { |
106 | - try { | |
107 | - Thread.sleep(TimeUnit.SECONDS.toMillis(pauseBetweenRetries)); | |
108 | - } catch (InterruptedException e) { | |
109 | - throw new RuntimeException(e); | |
119 | + if (expPauseBetweenRetries) { | |
120 | + long pause; | |
121 | + if (maxExpDegreeValue > expDegreeStep.get()) { | |
122 | + pause = new Double(Math.pow(pauseBetweenRetries, expDegreeStep.getAndIncrement())).longValue(); | |
123 | + } else { | |
124 | + pause = maxExpPauseBetweenRetries; | |
125 | + } | |
126 | + try { | |
127 | + Thread.sleep(TimeUnit.SECONDS.toMillis( | |
128 | + pause)); | |
129 | + } catch (InterruptedException e) { | |
130 | + throw new RuntimeException(e); | |
131 | + } | |
132 | + } else { | |
133 | + try { | |
134 | + Thread.sleep(TimeUnit.SECONDS.toMillis(pauseBetweenRetries)); | |
135 | + } catch (InterruptedException e) { | |
136 | + throw new RuntimeException(e); | |
137 | + } | |
110 | 138 | } |
111 | 139 | } |
112 | 140 | return new TbRuleEngineProcessingDecision(false, toReprocess); | ... | ... |
... | ... | @@ -725,6 +725,8 @@ queue: |
725 | 725 | retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited |
726 | 726 | failure-percentage: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; |
727 | 727 | pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_RETRY_PAUSE:3}"# Time in seconds to wait in consumer thread before retries; |
728 | + exp-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_EXP_RETRY_PAUSE:false}"# Parameter to enable/disable exponential increase of pause between retries; | |
729 | + max-exp-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_MAX_EXP_RETRY_PAUSE:86400}"# Max allowed time in seconds for pause between retries. | |
728 | 730 | - name: "${TB_QUEUE_RE_HP_QUEUE_NAME:HighPriority}" |
729 | 731 | topic: "${TB_QUEUE_RE_HP_TOPIC:tb_rule_engine.hp}" |
730 | 732 | poll-interval: "${TB_QUEUE_RE_HP_POLL_INTERVAL_MS:25}" |
... | ... | @@ -740,6 +742,8 @@ queue: |
740 | 742 | retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_RETRIES:0}" # Number of retries, 0 is unlimited |
741 | 743 | failure-percentage: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; |
742 | 744 | pause-between-retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_RETRY_PAUSE:5}"# Time in seconds to wait in consumer thread before retries; |
745 | + exp-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_EXP_RETRY_PAUSE:false}"# Parameter to enable/disable exponential increase of pause between retries; | |
746 | + max-exp-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_MAX_EXP_RETRY_PAUSE:86400}"# Max allowed time in seconds for pause between retries. | |
743 | 747 | - name: "${TB_QUEUE_RE_SQ_QUEUE_NAME:SequentialByOriginator}" |
744 | 748 | topic: "${TB_QUEUE_RE_SQ_TOPIC:tb_rule_engine.sq}" |
745 | 749 | poll-interval: "${TB_QUEUE_RE_SQ_POLL_INTERVAL_MS:25}" |
... | ... | @@ -755,6 +759,8 @@ queue: |
755 | 759 | retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited |
756 | 760 | failure-percentage: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; |
757 | 761 | pause-between-retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_RETRY_PAUSE:5}"# Time in seconds to wait in consumer thread before retries; |
762 | + exp-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_EXP_RETRY_PAUSE:false}"# Parameter to enable/disable exponential increase of pause between retries; | |
763 | + max-exp-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_MAX_EXP_RETRY_PAUSE:86400}"# Max allowed time in seconds for pause between retries. | |
758 | 764 | transport: |
759 | 765 | # For high priority notifications that require minimum latency and processing time |
760 | 766 | notifications_topic: "${TB_QUEUE_TRANSPORT_NOTIFICATIONS_TOPIC:tb_transport.notifications}" | ... | ... |
... | ... | @@ -24,5 +24,7 @@ public class TbRuleEngineQueueAckStrategyConfiguration { |
24 | 24 | private int retries; |
25 | 25 | private double failurePercentage; |
26 | 26 | private long pauseBetweenRetries; |
27 | + private boolean expPauseBetweenRetries; | |
28 | + private long maxExpPauseBetweenRetries; | |
27 | 29 | |
28 | 30 | } | ... | ... |