-
Couldn't load subscription status.
- Fork 11
fix(connect): mothership connection #1464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1470dd5
fix(connect): mothership connection
pujitm c82ad47
attempt mothership reconnection upon error
pujitm fb72e86
add recovery mechanism & delay client creation
pujitm cccc812
extract `MothershipController`; initialize onApplicationBootstrap
pujitm 6e5bc94
clarify docs around ip syncing issue
pujitm 1365f5f
re-add debounce
pujitm 0f48d6b
comment expected throws from mothership controller
pujitm 4f34c4b
don't trigger mothership restart when local & network ip's differ
pujitm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
59 changes: 59 additions & 0 deletions
59
packages/unraid-api-plugin-connect/src/mothership-proxy/mothership.controller.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { Injectable, Logger, OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common'; | ||
|
|
||
| import { TimeoutCheckerJob } from '../connection-status/timeout-checker.job.js'; | ||
| import { MothershipConnectionService } from './connection.service.js'; | ||
| import { MothershipGraphqlClientService } from './graphql.client.js'; | ||
| import { MothershipSubscriptionHandler } from './mothership-subscription.handler.js'; | ||
|
|
||
| /** | ||
| * Controller for (starting and stopping) the mothership stack: | ||
| * - GraphQL client (to mothership) | ||
| * - Subscription handler (websocket communication with mothership) | ||
| * - Timeout checker (to detect if the connection to mothership is lost) | ||
| * - Connection service (controller for connection state & metadata) | ||
| */ | ||
| @Injectable() | ||
| export class MothershipController implements OnModuleDestroy, OnApplicationBootstrap { | ||
| private readonly logger = new Logger(MothershipController.name); | ||
| constructor( | ||
| private readonly clientService: MothershipGraphqlClientService, | ||
| private readonly connectionService: MothershipConnectionService, | ||
| private readonly subscriptionHandler: MothershipSubscriptionHandler, | ||
| private readonly timeoutCheckerJob: TimeoutCheckerJob | ||
| ) {} | ||
|
|
||
| async onModuleDestroy() { | ||
| await this.stop(); | ||
| } | ||
|
|
||
| async onApplicationBootstrap() { | ||
| await this.initOrRestart(); | ||
| } | ||
|
|
||
| /** | ||
| * Stops the mothership stack. Throws on first error. | ||
| */ | ||
| async stop() { | ||
| this.timeoutCheckerJob.stop(); | ||
| this.subscriptionHandler.stopMothershipSubscription(); | ||
| await this.clientService.clearInstance(); | ||
| this.connectionService.resetMetadata(); | ||
| this.subscriptionHandler.clearAllSubscriptions(); | ||
| } | ||
|
|
||
| /** | ||
| * Attempts to stop, then starts the mothership stack. Throws on first error. | ||
| */ | ||
| async initOrRestart() { | ||
| await this.stop(); | ||
| const { state } = this.connectionService.getIdentityState(); | ||
| this.logger.verbose('cleared, got identity state'); | ||
| if (!state.apiKey) { | ||
| this.logger.warn('No API key found; cannot setup mothership subscription'); | ||
| return; | ||
| } | ||
| await this.clientService.createClientInstance(); | ||
| await this.subscriptionHandler.subscribeToMothershipEvents(); | ||
| this.timeoutCheckerJob.start(); | ||
| } | ||
pujitm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.