-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(websocket): pluging websocket and storing result in slices
- Loading branch information
Showing
36 changed files
with
4,483 additions
and
4,025 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './lib/colors.enum' | ||
export * from './lib/icon.enum' | ||
export * from './lib/running-status.enum' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export enum RunningStatus { | ||
STARTING = 'STARTING', | ||
RUNNING = 'RUNNING', | ||
WARNING = 'WARNING', | ||
ERROR = 'ERROR', | ||
STOPPING = 'STOPPING', | ||
STOPPED = 'STOPPED', | ||
TERMINATED = 'TERMINATED', | ||
UNKNOWN = 'UNKNOWN', | ||
} |
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
10 changes: 10 additions & 0 deletions
10
libs/shared/interfaces/src/lib/common/websocket-running-status.interface.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ServiceRunningStatus } from '../domain/service-running-status.interface' | ||
import { RunningStatus } from '@console/shared/enums' | ||
|
||
export interface WebsocketRunningStatusInterface { | ||
applications?: ServiceRunningStatus[] | ||
database?: ServiceRunningStatus[] | ||
id: string | ||
project_id: string | ||
state: RunningStatus | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { Environment, Status } from 'qovery-typescript-axios' | ||
import { WebsocketRunningStatusInterface } from '../common/websocket-running-status.interface' | ||
|
||
export interface EnvironmentEntity extends Environment { | ||
status?: Status | ||
running_status?: WebsocketRunningStatusInterface | ||
} |
12 changes: 12 additions & 0 deletions
12
libs/shared/interfaces/src/lib/domain/service-running-status.interface.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RunningStatus } from '@console/shared/enums' | ||
|
||
export interface ServiceRunningStatus { | ||
id: string | ||
state: RunningStatus | ||
pods: { | ||
name: string | ||
state: RunningStatus | ||
restart_count: 0 | ||
state_message: string | ||
}[] | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
...ed/utils/src/lib/hooks/use-running-status-websocket/use-running-status-websocket.spec.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import useRunningStatusWebsocket from './use-running-status-websocket' | ||
|
||
describe('Running Status Websocket Provider', () => { | ||
it('should render successfully', () => { | ||
const { result } = renderHook(() => useRunningStatusWebsocket()) | ||
|
||
expect(result).toBeTruthy() | ||
}) | ||
}) |
51 changes: 51 additions & 0 deletions
51
.../shared/utils/src/lib/hooks/use-running-status-websocket/use-running-status-websocket.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useState } from 'react' | ||
import useAuth from '../../http/use-auth/use-auth' | ||
|
||
export interface RunningStatusWebsocketProps { | ||
organizationId: string | ||
} | ||
|
||
const baseUrl = 'wss://ws.qovery.com/service/status' | ||
|
||
export function useRunningStatusWebsocket() { | ||
const [websockets, setWebsockets] = useState<string[]>([]) | ||
const [websocketsUrl, setWebsocketsUrl] = useState<string[]>([]) | ||
const { getAccessTokenSilently } = useAuth() | ||
|
||
const closeSockets = (): void => { | ||
setWebsockets([]) | ||
setWebsocketsUrl([]) | ||
} | ||
|
||
const openWebSockets = async (organizationId: string, clusterIds: string[]): Promise<string[]> => { | ||
clusterIds.forEach((clusterId) => { | ||
openWebSocket(organizationId, clusterId) | ||
}) | ||
|
||
return [] | ||
} | ||
|
||
const openWebSocket = async (organizationId: string, clusterId: string): Promise<void> => { | ||
const token = await getAccessTokenSilently() | ||
|
||
setWebsockets((prevValue) => { | ||
const webSocketId = `${organizationId}-${clusterId}` | ||
if (prevValue.indexOf(webSocketId) === -1) return [...prevValue, webSocketId] | ||
return prevValue | ||
}) | ||
setWebsocketsUrl((prevValue) => { | ||
const webSocketUrl = `${baseUrl}?organization=${organizationId}&cluster=${clusterId}&bearer_token=${token}` | ||
if (prevValue.indexOf(webSocketUrl) === -1) return [...prevValue, webSocketUrl] | ||
return prevValue | ||
}) | ||
} | ||
|
||
return { | ||
websockets, | ||
websocketsUrl, | ||
closeSockets, | ||
openWebSockets, | ||
} | ||
} | ||
|
||
export default useRunningStatusWebsocket |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { shortToLongId } from './short-to-long-id' | ||
|
||
describe('finding the long id from the short id', () => { | ||
const listIds = ['f9613eb4-1bfa-4b74-85bc-864e7fb72abd', '61d95abd-b777-4f53-b832-58c7e7f6f1bf'] | ||
|
||
it('should use the short id to find the associated long id in the list', () => { | ||
const shortId = 'z61d95abd' | ||
const foundId = shortToLongId(shortId, listIds) | ||
expect(foundId).toEqual('61d95abd-b777-4f53-b832-58c7e7f6f1bf') | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const shortToLongId = (id: string, listIds: string[]): string => { | ||
if (id[0] !== 'z') return id | ||
id = id.slice(1) | ||
|
||
return listIds.find((theId) => theId.indexOf(id) >= 0) || id | ||
} |
Oops, something went wrong.