Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

refactor(client-core)(server-info service): remove action receptor usage #8327

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 30 additions & 76 deletions packages/client-core/src/admin/services/ServerInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ Ethereal Engine. All Rights Reserved.
*/

import { ServerInfoInterface, ServerPodInfo } from '@etherealengine/common/src/interfaces/ServerInfo'
import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux'
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { defineState, getMutableState } from '@etherealengine/hyperflux'

import { API } from '../../API'
import { NotificationService } from '../../common/services/NotificationService'

//State
export const AdminServerInfoState = defineState({
name: 'AdminServerInfoState',
initial: () => ({
Expand All @@ -41,82 +39,38 @@ export const AdminServerInfoState = defineState({
})
})

const fetchServerInfoRequestedReceptor = (
action: typeof AdminServerInfoActions.fetchServerInfoRequested.matches._TYPE
) => {
try {
const state = getMutableState(AdminServerInfoState)
return state.merge({ retrieving: true })
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
}

const fetchServerInfoRetrievedReceptor = (
action: typeof AdminServerInfoActions.fetchServerInfoRetrieved.matches._TYPE
) => {
try {
const state = getMutableState(AdminServerInfoState)
return state.merge({
servers: action.data,
retrieving: false,
fetched: true,
updateNeeded: false
})
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
}

const serverInfoPodRemovedReceptor = (action: typeof AdminServerInfoActions.serverInfoPodRemoved.matches._TYPE) => {
const state = getMutableState(AdminServerInfoState)
return state.merge({ updateNeeded: true })
}

export const AdminServerInfoReceptors = {
fetchServerInfoRequestedReceptor,
fetchServerInfoRetrievedReceptor,
serverInfoPodRemovedReceptor
}

//Service
export const ServerInfoService = {
fetchServerInfo: async () => {
dispatchAction(AdminServerInfoActions.fetchServerInfoRequested({}))

let serverInfo: ServerInfoInterface[] = await API.instance.client.service('server-info').find()
const allPods: ServerPodInfo[] = []
for (const item of serverInfo) {
allPods.push(...item.pods)
getMutableState(AdminServerInfoState).merge({ retrieving: true })
try {
let serverInfo: ServerInfoInterface[] = await Engine.instance.api.service('server-info').find()
const allPods: ServerPodInfo[] = []
for (const item of serverInfo) {
allPods.push(...item.pods)
}

serverInfo = [
{
id: 'all',
label: 'All',
pods: allPods
},
...serverInfo
]

getMutableState(AdminServerInfoState).merge({
servers: serverInfo,
retrieving: false,
fetched: true,
updateNeeded: false
})
} catch (err) {
getMutableState(AdminServerInfoState).merge({ retrieving: true })
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}

serverInfo = [
{
id: 'all',
label: 'All',
pods: allPods
},
...serverInfo
]

dispatchAction(AdminServerInfoActions.fetchServerInfoRetrieved({ data: serverInfo }))
},
removePod: async (podName: string) => {
await API.instance.client.service('server-info').remove(podName)
dispatchAction(AdminServerInfoActions.serverInfoPodRemoved({}))
await Engine.instance.api.service('server-info').remove(podName)
getMutableState(AdminServerInfoState).merge({ updateNeeded: true })
}
}

//Action
export class AdminServerInfoActions {
static fetchServerInfoRequested = defineAction({
type: 'ee.client.AdminServerInfo.FETCH_SERVER_INFO_REQUESTED' as const
})
static fetchServerInfoRetrieved = defineAction({
type: 'ee.client.AdminServerInfo.FETCH_SERVER_INFO_RETRIEVED' as const,
data: matches.array as Validator<unknown, ServerInfoInterface[]>
})
static serverInfoPodRemoved = defineAction({
type: 'ee.client.AdminLocation.SERVER_INFO_POD_REMOVED' as const
})
}
9 changes: 0 additions & 9 deletions packages/client-core/src/systems/AdminSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { AdminResourceActions, AdminResourceReceptors } from '../admin/services/
import { AdminRouteActions, AdminRouteReceptors } from '../admin/services/RouteService'
import { AdminSceneActions, AdminSceneReceptors } from '../admin/services/SceneService'
import { AdminScopeTypeActions, AdminScopeTypeReceptor } from '../admin/services/ScopeTypeService'
import { AdminServerInfoActions, AdminServerInfoReceptors } from '../admin/services/ServerInfoService'
import { AdminServerLogsActions, AdminServerLogsReceptors } from '../admin/services/ServerLogsService'
// import { AuthSettingsActions, AuthSettingsReceptors } from '../admin/services/Setting/AuthSettingService'
import { AdminAwsSettingActions, AwsSettingReceptors } from '../admin/services/Setting/AwsSettingService'
Expand All @@ -72,9 +71,6 @@ import {
import { AdminTestBotActions, AdminTestBotReceptors } from '../admin/services/TestBotService'

const fetchedTaskServersQueue = defineActionQueue(AdminTaskServerSettingActions.fetchedTaskServers.matches)
const fetchServerInfoRequestedQueue = defineActionQueue(AdminServerInfoActions.fetchServerInfoRequested.matches)
const fetchServerInfoRetrievedQueue = defineActionQueue(AdminServerInfoActions.fetchServerInfoRetrieved.matches)
const serverInfoPodRemovedQueue = defineActionQueue(AdminServerInfoActions.serverInfoPodRemoved.matches)
const fetchServerLogsRequestedQueue = defineActionQueue(AdminServerLogsActions.fetchServerLogsRequested.matches)
const fetchServerLogsRetrievedQueue = defineActionQueue(AdminServerLogsActions.fetchServerLogsRetrieved.matches)
const redisSettingRetrievedQueue = defineActionQueue(AdminRedisSettingActions.redisSettingRetrieved.matches)
Expand Down Expand Up @@ -153,11 +149,6 @@ const singleRecordingRetrievedQueue = defineActionQueue(AdminSingleRecordingsAct

const execute = () => {
for (const action of fetchedTaskServersQueue()) TaskServerSettingReceptors.fetchedTaskServersReceptor(action)
for (const action of fetchServerInfoRequestedQueue())
AdminServerInfoReceptors.fetchServerInfoRequestedReceptor(action)
for (const action of fetchServerInfoRetrievedQueue())
AdminServerInfoReceptors.fetchServerInfoRetrievedReceptor(action)
for (const action of serverInfoPodRemovedQueue()) AdminServerInfoReceptors.serverInfoPodRemovedReceptor(action)
for (const action of fetchServerLogsRequestedQueue())
AdminServerLogsReceptors.fetchServerLogsRequestedReceptor(action)
for (const action of fetchServerLogsRetrievedQueue())
Expand Down