message_bus 4.3.0 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f725f70ad14bdd643aea469118faba0c666f36c47ec6fc3b33dc3c2db85ee8fb
4
- data.tar.gz: faf76a2ef12077e48890250b60572700076d0d9da317df2f91d96d49f514e002
3
+ metadata.gz: 15a820bf3ce7658e466132cbc2dd41c4f71b5c68db2e993437698192922377b9
4
+ data.tar.gz: 2c698b0e82d3d17dc3c0aa682e34ffaf32713f47fe207c1e8b1d55d2fb7cbe48
5
5
  SHA512:
6
- metadata.gz: a73153925e4bd93e5dcc2b8d09c18b944f074bcac7b9de563923e7ac3abd0552951f89418f09d58682fa41748810491cb3e6cfbc24fef1c6f32c7b397724e8a5
7
- data.tar.gz: 659ebc5f7c22af1ab1dbd23247896e51511394bdad062816bb25174f1fc5d8d474171fc4d8d2a7e989f2a6eda700e4fe38b8caa7bf575a70319e5d318ee18f9f
6
+ metadata.gz: 0ea1a5c7a8c80bdddb487eed1442e6364b37518407c1809b0fe76bc3bf5fcba96bb66df04d02d4e491350d415abbae1cd0ecc91ef1079838d6455b6063c0459f
7
+ data.tar.gz: 981cc3d93b7ca7a3af50179c9450033f4e4566edca5d1269c73d3fd94952f5a77d5ce14b87aa58bc5845e377a2c5c6cbe64cd1dc7905dd7689dfe1295f0668cf
data/.eslintrc.js CHANGED
@@ -11,4 +11,13 @@ module.exports = {
11
11
  },
12
12
  rules: {},
13
13
  ignorePatterns: ['/vendor', '/doc', '/assets/jquery-1.8.2.js'],
14
+ overrides: [
15
+ {
16
+ // Enable async/await in tests only
17
+ files: ["spec/**/*"],
18
+ parserOptions: {
19
+ ecmaVersion: 2022,
20
+ },
21
+ },
22
+ ],
14
23
  };
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  FUTURE
2
2
 
3
+ 06-01-2023
4
+
5
+ - Version 4.2.1
6
+
7
+ - FIX: Ensure non-long-polling requests are always spaced out
8
+
3
9
  04-11-2022
4
10
 
5
11
  - Version 4.2.0
@@ -40,7 +40,7 @@
40
40
  var pollTimeout = null;
41
41
  var totalAjaxFailures = 0;
42
42
  var totalAjaxCalls = 0;
43
- var lastAjax;
43
+ var lastAjaxStartedAt;
44
44
 
45
45
  var isHidden = (function () {
46
46
  var prefixes = ["", "webkit", "ms", "moz"];
@@ -156,11 +156,11 @@
156
156
  }
157
157
 
158
158
  var gotData = false;
159
- var aborted = false;
159
+ var abortedByClient = false;
160
160
  var rateLimited = false;
161
161
  var rateLimitedSeconds;
162
162
 
163
- lastAjax = new Date();
163
+ lastAjaxStartedAt = new Date();
164
164
  totalAjaxCalls += 1;
165
165
  data.__seq = totalAjaxCalls;
166
166
 
@@ -281,7 +281,7 @@
281
281
  rateLimitedSeconds = tryAfter;
282
282
  rateLimited = true;
283
283
  } else if (textStatus === "abort") {
284
- aborted = true;
284
+ abortedByClient = true;
285
285
  } else {
286
286
  failCount += 1;
287
287
  totalAjaxFailures += 1;
@@ -290,27 +290,40 @@
290
290
  complete: function () {
291
291
  ajaxInProgress = false;
292
292
 
293
- var interval;
293
+ var inLongPollingMode = shouldLongPoll();
294
+ var startNextRequestAfter;
294
295
  try {
295
296
  if (rateLimited) {
296
- interval = Math.max(me.minPollInterval, rateLimitedSeconds * 1000);
297
- } else if (gotData || aborted) {
298
- interval = me.minPollInterval;
297
+ // Respect `Retry-After` header
298
+ startNextRequestAfter = Math.max(
299
+ me.minPollInterval,
300
+ rateLimitedSeconds * 1000
301
+ );
302
+ } else if (abortedByClient) {
303
+ // Immediately trigger another poll
304
+ startNextRequestAfter = me.minPollInterval;
305
+ } else if (failCount > 2) {
306
+ // Linear backoff up to maxPollInterval
307
+ startNextRequestAfter = Math.min(
308
+ me.callbackInterval * failCount,
309
+ me.maxPollInterval
310
+ );
311
+ } else if (inLongPollingMode && gotData) {
312
+ // Immediately trigger another poll
313
+ startNextRequestAfter = me.minPollInterval;
299
314
  } else {
300
- interval = me.callbackInterval;
301
- if (failCount > 2) {
302
- interval = interval * failCount;
303
- } else if (!shouldLongPoll()) {
304
- interval = me.backgroundCallbackInterval;
305
- }
306
- if (interval > me.maxPollInterval) {
307
- interval = me.maxPollInterval;
308
- }
315
+ // Trigger next poll N seconds after the last one **started**
316
+ var targetRequestInterval = inLongPollingMode
317
+ ? me.callbackInterval
318
+ : me.backgroundCallbackInterval;
319
+
320
+ var elapsedSinceLastAjaxStarted = new Date() - lastAjaxStartedAt;
309
321
 
310
- interval -= new Date() - lastAjax;
322
+ startNextRequestAfter =
323
+ targetRequestInterval - elapsedSinceLastAjaxStarted;
311
324
 
312
- if (interval < 100) {
313
- interval = 100;
325
+ if (startNextRequestAfter < 100) {
326
+ startNextRequestAfter = 100;
314
327
  }
315
328
  }
316
329
  } catch (e) {
@@ -328,7 +341,7 @@
328
341
  pollTimeout = setTimeout(function () {
329
342
  pollTimeout = null;
330
343
  poll();
331
- }, interval);
344
+ }, startNextRequestAfter);
332
345
  }
333
346
 
334
347
  me.longPoll = null;
@@ -367,7 +380,9 @@
367
380
  totalAjaxFailures
368
381
  );
369
382
  console.log(
370
- "Last ajax call: " + (new Date() - lastAjax) / 1000 + " seconds ago"
383
+ "Last ajax call: " +
384
+ (new Date() - lastAjaxStartedAt) / 1000 +
385
+ " seconds ago"
371
386
  );
372
387
  },
373
388
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MessageBus
4
- VERSION = "4.3.0"
4
+ VERSION = "4.3.1"
5
5
  end