Created
February 13, 2019 06:25
-
-
Save maxfi/90681baeffc85c31c2c5a31bf561e809 to your computer and use it in GitHub Desktop.
[Meteor custom reconnect] #meteor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Meteor } from 'meteor/meteor' | |
import _ from 'lodash/fp' | |
Meteor.startup(() => { | |
Tracker.autorun(() => { | |
const { status, retryCount } = Meteor.status() | |
if ((status === 'waiting') && (retryCount >= 5)) { | |
const interval = _.random(0, 1000 * 120) | |
Meteor.disconnect() | |
console.warn(`5 or more reconnection attempts. Reconnecting in ${interval} ms.`, Meteor.status()) | |
Meteor.setTimeout(() => { | |
console.debug('Reconnecting...') | |
Meteor.reconnect() | |
}, interval) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment