mirror of
https://github.com/unraid/api.git
synced 2026-01-10 18:50:11 -06:00
fix: reconnect to mothership's subcription endpoint on key change
This commit is contained in:
@@ -8,6 +8,9 @@ import { coreLogger } from '../log';
|
||||
import { paths } from '../paths';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { loadState } from '../utils';
|
||||
import { mothership } from '../../mothership/subscribe-to-servers';
|
||||
import { apiManager } from '../api-manager';
|
||||
import { MessageTypes } from 'subscriptions-transport-ws';
|
||||
|
||||
export const myservers = () => {
|
||||
const watchers: chokidar.FSWatcher[] = [];
|
||||
@@ -37,10 +40,37 @@ export const myservers = () => {
|
||||
// missing it's likely we shipped without Sentry
|
||||
// initialised. This would be done for a reason!
|
||||
if (sentryClient) {
|
||||
sentryClient.getOptions().enabled = isEnabled;
|
||||
// Check if the value changed
|
||||
if (sentryClient.getOptions().enabled !== isEnabled) {
|
||||
sentryClient.getOptions().enabled = isEnabled;
|
||||
|
||||
// Log for debugging
|
||||
coreLogger.debug('%s crash reporting!', isEnabled ? 'Enabled' : 'Disabled');
|
||||
// Log for debugging
|
||||
coreLogger.debug('%s crash reporting!', isEnabled ? 'Enabled' : 'Disabled');
|
||||
}
|
||||
}
|
||||
|
||||
// If we have no my_servers key disconnect from mothership's subscription endpoint
|
||||
if (apiManager.getValidKeys().filter(key => key.name === 'my_servers').length === 0) {
|
||||
// Disconnect forcefully from mothership so we ensure it doesn't reconnect automatically
|
||||
mothership.close(true, true);
|
||||
}
|
||||
|
||||
// If we have a my_servers key reconnect to mothership
|
||||
if (apiManager.getValidKeys().filter(key => key.name === 'my_servers').length === 1) {
|
||||
// Reconnect to mothership
|
||||
mothership.connect();
|
||||
|
||||
// Reregister all subscriptions
|
||||
// @ts-expect-error
|
||||
Object.keys(mothership.operations).forEach(id => {
|
||||
mothership.sendMessage(
|
||||
id,
|
||||
// @ts-expect-error
|
||||
MessageTypes.GQL_START,
|
||||
// @ts-expect-error
|
||||
mothership.operations[id].options
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import { MOTHERSHIP_GRAPHQL_LINK, ONE_SECOND } from '../consts';
|
||||
import { userCache, CachedServers } from '../cache';
|
||||
|
||||
const log = logger.createChild({ prefix: 'subscribe-to-servers' });
|
||||
const client = new SubscriptionClient(MOTHERSHIP_GRAPHQL_LINK, {
|
||||
reconnect: true,
|
||||
export const mothership = new SubscriptionClient(MOTHERSHIP_GRAPHQL_LINK, {
|
||||
reconnect: false,
|
||||
lazy: true,
|
||||
minTimeout: ONE_SECOND * 30,
|
||||
connectionCallback: errors => {
|
||||
@@ -23,7 +23,7 @@ const client = new SubscriptionClient(MOTHERSHIP_GRAPHQL_LINK, {
|
||||
|
||||
export const subscribeToServers = async (apiKey: string) => {
|
||||
log.silly('Subscribing to servers with %s', apiKey);
|
||||
const query = client.request({
|
||||
const query = mothership.request({
|
||||
query: `subscription servers ($apiKey: String!) {
|
||||
servers @auth(apiKey: $apiKey)
|
||||
}`,
|
||||
|
||||
Reference in New Issue
Block a user