-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/ping services #23
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
base: main
Are you sure you want to change the base?
Conversation
… into feature/ping-services � Conflicts: � package.json
… into feature/ping-services
Statuses now are pushing to db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ещё пофикси ts. Тогда потестирую на локали и апрувну.
src/config/index.ts
Outdated
@@ -27,4 +27,8 @@ export default class Config { | |||
* Workspaces config-file path | |||
*/ | |||
public static workspacesConfigPath: string = process.env.CONFIG_FILE || ''; | |||
/** | |||
* Cron schedule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
непонятное описание
src/controllers/statuses.ts
Outdated
import ServerService from '../services/server'; | ||
|
||
/** | ||
* Statuses controller |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
непонятное описание
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все еще
src/controllers/statuses.ts
Outdated
* Update statuses and send to logged users | ||
*/ | ||
public static async updateStatuses(): Promise<void> { | ||
const users = app.context.transport.clients.find(client => !!client).toArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем этот find?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Чтобы вернуть всех клиентов
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
чтобы вернуть всех, не нужно делать поиск по массиву
src/controllers/statuses.ts
Outdated
|
||
for (const workspaceAggregation of workspaceAggregations) { | ||
const serverServicesStatuses: ServiceStatus = {} as ServiceStatus; | ||
const serviceList = workspaceAggregation.servicesList[0].projectName.flat(Infinity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все равно magic number
src/controllers/statuses.ts
Outdated
if (ws) { | ||
const workspaceAggregations = await WorkspacesService.aggregateServices(ws._id); | ||
|
||
for (const workspaceAggregation of workspaceAggregations) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
непонятный код, нужно добавить комментариев
src/services/server.ts
Outdated
import ServiceStatus from '../database/models/serverServicesStatuses'; | ||
|
||
/** | ||
* Server service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
описание дублирует название
src/controllers/statuses.ts
Outdated
public static async pingProjects(serviceType:string, workspaceAggregation: WorkspacesAggregation, serverServicesStatuses: ServiceStatus = {} as ServiceStatus): Promise<void> { | ||
if (serviceType === 'nginx') { | ||
const projectList = workspaceAggregation.servers.services.payload; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А нельзя просто принять projectList
?
src/controllers/statuses.ts
Outdated
for (const project of projectList) { | ||
projects.push(project.serverName as string); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Может тут использовать map
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/controllers/statuses.ts
Outdated
public static async pingProjects(workspaceAggregation: WorkspacesAggregation, serverServicesStatuses: ServiceStatus = {} as ServiceStatus): Promise<void> { | ||
const serviceType = workspaceAggregation.servers.services.type; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А может просто передать workspaceAgregation.servers
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужен рефакторинг
src/controllers/statuses.ts
Outdated
/** | ||
* If type of service is nginx, server's projects are pinged | ||
*/ | ||
await this.pingProjects(w.servers, serverServicesStatuses); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
функция называется pingProjects
, а принимает servers
. Надо назватьpingServers
, судя по всему
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и зачем она принимает serverServicesStatuses
? Она же сама должна пинговать, судя по названию.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и почему она принимает несколько серверов? Лучше сделать, чтобы принимала один конкретный хост и пинговала его
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в servers тип + проекты какого-то сервера
src/controllers/statuses.ts
Outdated
* @param serverServicesStatuses - object with serverToken and statuses of server's projects | ||
*/ | ||
public static async pingProjects(workspaceAggregationServer: IServer, serverServicesStatuses: ServiceStatus = {} as ServiceStatus): Promise<void> { | ||
const serviceType = workspaceAggregationServer.services.type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не понятно, что такое services.type
. Type
может быть у одного какого-то сервиса
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и зачем сюда передавать какой-то не понятный объект workspaceAggregationServer
. Надо передать один конкретный хост. Функция должна вернуть результат пинга. Обновление статуса в базе надо отсюда вынести. Ну или как-то соответствующим образом поменять название метода.
src/controllers/statuses.ts
Outdated
projectList.forEach((project) => { | ||
projects.push(project.serverName as string); | ||
}); | ||
const projectsStatuses = await StatusesController.checkingProjectsAvailability(projects); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что такое checkingProjectsAvailability
? почему нет глагола и почему передается сразу несколько проектов? пинговать же можно один какой-то хост.
src/services/server.ts
Outdated
* @param serviceStatuses - services' statuses and server token | ||
*/ | ||
public static async updateServicesStatuses(serviceStatuses: IServiceStatus): Promise<mongoose.Document> { | ||
const server = await ServiceStatus.findOne({ serverToken: serviceStatuses.serverToken }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему в переменную server записывается не сервер, а какой-то статус?
src/controllers/statuses.ts
Outdated
/** | ||
* Get workspace servers and their projects | ||
*/ | ||
const workspaceAggregations: WorkspacesAggregation[] = await WorkspacesService.aggregateServices(workspace._id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эта агрегация портит структуру кода. Почему просто не взять workspace.servers циклом?
comments will be removed at next pr
src/controllers/statuses.ts
Outdated
* | ||
* @param projectList - list of project of payload of some service of some server | ||
*/ | ||
public static async pingProjects(projectList: Record<string, unknown>[]): Promise<ProjectStatus[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему Record<string, unknown>[]
? Нам же известна структура
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
у payload должен быть Union Type с перечислением NginxPayload | DockerPayload | ...
src/controllers/statuses.ts
Outdated
*/ | ||
if (service.type == 'nginx') { | ||
const projectsStatuses = await this.pingProjects(service.payload); | ||
const serverProjectsStatuses: ServerProjectsStatuses = {} as ServerProjectsStatuses; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно сразу написать
const serverProjectsStatuses: ServerProjectsStatuses = {
projectsStatuses,
serverToken: s.token
}
src/services/server.ts
Outdated
* | ||
* @param serviceStatuses - services' statuses and server token | ||
*/ | ||
public static async updateServicesStatuses(serviceStatuses: IServiceStatus): Promise<mongoose.Document> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут все еще бардак
updateServicesStatuses — статусы сервисов
serviceStatuses - статусы сервиса
ServiceStatus.updateOne - статус сервиса
а обновление происходит по serverToken
, значит это обновление инфы о сервере, то есть в названии должно быть что-то типа updateServerPojectsStatuses
src/services/server.ts
Outdated
await this.add(serviceStatuses); | ||
} | ||
|
||
return ServiceStatus.updateOne({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а что такое ServiceStatus? они же лежат в одной таблице workspaces
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему то по shift+fn+f6 не везде заменило имена, сейчас исправлю
src/controllers/statuses.ts
Outdated
import ping from 'ping'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars-experimental,@typescript-eslint/no-unused-vars | ||
import app from './../app'; | ||
import WorkspacesService from './../services/workspace'; | ||
import ServerProjectsStatuses, { ProjectStatus } from '../types/serverProjectsStatuses'; | ||
import IWorkspace from './../types/workspace'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import Client from 'ctproto/build/src/server/client'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import { DevopsToolboxAuthData } from '../types/api/responses/authorize'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import { ApiOutgoingMessage, ApiResponse } from '../types'; | ||
import Server from '../services/server'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import WorkspaceAggregation, { Server as IServer } from '../types/workspaceAggregation'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А eslint-disable
нужны?
// public static sendStatuses(statuses: ServerProjectsStatuses[], user: Client<DevopsToolboxAuthData, ApiResponse, ApiOutgoingMessage>): void { | ||
// if (typeof user.authData.userToken === 'string') { | ||
// app.context.transport | ||
// .clients | ||
// .find((client) => client.authData.userToken === user.authData.userToken) | ||
// .send('statuses-updated', { statuses }); | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если это тебе не нужно, то можно убрать это вообще
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
комменты уберу в некст реквесте
src/types/serverProjectsStatuses.ts
Outdated
@@ -0,0 +1,28 @@ | |||
import * as mongoose from 'mongoose'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему не просто import mongoose from 'mongoose'
?
src/types/workspaceAggregation.ts
Outdated
|
||
/** | ||
* Interface for server | ||
*/ | ||
export interface Server { | ||
/** | ||
* Server name | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* Integration token | ||
* given on server creation | ||
*/ | ||
token: string; | ||
|
||
/** | ||
* Information for SSH connection to server | ||
*/ | ||
sshConnectionInfo: SSHConnectionInfo; | ||
|
||
/** | ||
* List of services running on the server | ||
*/ | ||
services: Service[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем это надо? Нельзя ли просто import Server from './server'
?
src/controllers/statuses.ts
Outdated
/** | ||
* Get workspace servers and their projects | ||
*/ | ||
const workspaceAggregations: WorkspaceAggregation[] = await WorkspacesService.aggregateServices(workspace._id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
объясни плз, зачем делать доп запросы в базу. Разве переменная workspaces
не содержит серверы и сервисы?
src/controllers/statuses.ts
Outdated
* | ||
* @param projectList - list of project of payload of some service of some server | ||
*/ | ||
public static async pingProjects(projectList: Record<string, unknown>[]): Promise<ProjectStatus[]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
у payload должен быть Union Type с перечислением NginxPayload | DockerPayload | ...
src/services/server.ts
Outdated
* @param serverProjectsStatuses - server projects' statuses and server token | ||
*/ | ||
public static async updateServicesStatuses(serverProjectsStatuses: ServerProjectsStatuses): Promise<mongoose.Document> { | ||
const server = await IServerProjectsStatuses.findOne({ serverToken: serverProjectsStatuses.serverToken }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Префикс I
означает интерфейс. А у тебя тут какой то класс с таким префиксом
@@ -0,0 +1,33 @@ | |||
export interface Port { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs
src/types/service.ts
Outdated
export interface NginxService extends Service<NginxPayload> { | ||
type: 'nginx'; | ||
} | ||
export interface DockerService extends Service<DockerPayload> { | ||
type: 'docker'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs
src/controllers/statuses.ts
Outdated
for (const project of projectList) { | ||
projectsStatuses.push(await StatusesController.checkProjectAvailability(project['serverName'] as string)); | ||
for (const payloadElement of payload) { | ||
projectsStatuses.push(await StatusesController.checkProjectAvailability(payloadElement.serverName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы вынес это в переменную
src/controllers/statuses.ts
Outdated
projectsStatuses, | ||
serverToken: s.token, | ||
} as ServerProjectsStatuses; | ||
if (service.type == 'nginx') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы ===
поставил
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В чем надобность?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну тут особо разницы нет. Просто мы вроде везде используем ===
src/types/servicePayload.ts
Outdated
/** | ||
* Host for inside container | ||
*/ | ||
host: string, | ||
/** | ||
* Port for inside container | ||
*/ | ||
port: string, | ||
/** | ||
* Type of inside container | ||
*/ | ||
type: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему бы не вынести этот код в отдельный интерфейс, чтобы не дублировать его?
src/types/servicePayload.ts
Outdated
listen: string, | ||
serverName: string, | ||
proxyPass: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
доки?
src/types/servicePayload.ts
Outdated
names: string, | ||
containerId: string, | ||
image: string, | ||
created: Date, | ||
status: string, | ||
ports: Port[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тоже доки
src/index.ts
Outdated
* Ping availability of connected user's services | ||
*/ | ||
cron.schedule(Config.pingSchedule, () => { | ||
StatusesController.updateStatuses(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
промис надо обработать
// eslint-disable-next-line @typescript-eslint/no-unused-vars-experimental,@typescript-eslint/no-unused-vars | ||
import app from './../app'; | ||
import WorkspacesService from './../services/workspace'; | ||
import ServerProjectsStatuses, { ProjectStatus } from '../types/serverProjectsStatuses'; | ||
import Workspace from './../types/workspace'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import Client from 'ctproto/build/src/server/client'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import { DevopsToolboxAuthData } from '../types/api/responses/authorize'; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental | ||
import { ApiOutgoingMessage, ApiResponse } from '../types'; | ||
import Server from '../services/server'; | ||
import { NginxPayload } from '../types/servicePayload'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unused-vars-experimental |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что за беспредел
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В следующем реквесте уберу..
Uh oh!
There was an error while loading. Please reload this page.