Skip to content

Commit c20b6bb

Browse files
committed
Remove timeseries from server
1 parent 915bb68 commit c20b6bb

File tree

4 files changed

+4
-383
lines changed

4 files changed

+4
-383
lines changed

server/src/index.ts

-227
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import { Client as PgClient } from 'pg'
21
import { Options, ServerOptions } from './types'
32
import { SelvaServer, startServer } from './server'
4-
import PostgresManager from './server/postgresManager'
5-
import { startTimeseriesWorker } from './server/timeseriesWorker'
63
import getPort from 'get-port'
74
import chalk from 'chalk'
85
import os from 'os'
96
import { join } from 'path'
107
import fs from 'fs'
118
import { TextServer } from './server/text'
129
import mkdirp from 'mkdirp'
13-
import updateRegistry from './server/updateRegistry'
14-
import updateTimeseriesRegistry from './server/updateTimeseriesRegistry'
15-
import { connect, ServerDescriptor } from '@saulx/selva'
1610

1711
export * as s3Backups from './backup-plugins/s3'
1812

19-
export { startTimeseriesWorker }
20-
2113
const resolveOpts = async (opts: Options): Promise<ServerOptions> => {
2214
let parsedOpts: ServerOptions
2315
if (typeof opts === 'function') {
@@ -222,94 +214,6 @@ export async function startTimeseriesRegistry(opts: Options) {
222214
return startServer('timeseriesRegistry', parsedOpts)
223215
}
224216

225-
export async function startTimeseries(opts: Options) {
226-
const parsedOpts = await resolveOpts(opts)
227-
228-
// TODO
229-
const password = 'baratta'
230-
const host = '127.0.0.1'
231-
232-
const db = new PostgresManager({
233-
port: parsedOpts.port,
234-
password,
235-
name: `main`,
236-
})
237-
db.start()
238-
239-
// client ready check
240-
let ctr = 0
241-
while (ctr < 1000) {
242-
++ctr
243-
try {
244-
const client = new PgClient({
245-
connectionString: `postgres://postgres:${password}@${host}:${parsedOpts.port}`,
246-
})
247-
await client.connect()
248-
await client.query(`select 1`, [])
249-
client.end()
250-
break
251-
} catch (e) {
252-
// nop
253-
}
254-
await new Promise((resolve) => setTimeout(resolve, 1000))
255-
}
256-
257-
const selvaClient = connect(parsedOpts.registry)
258-
259-
const tsServer = {
260-
isDestroyed: false,
261-
pm: db,
262-
selvaClient,
263-
}
264-
265-
const info: ServerDescriptor = {
266-
type: 'timeseries',
267-
port: parsedOpts.port,
268-
host: parsedOpts.host,
269-
}
270-
271-
db.on('stats', (rawStats) => {
272-
if (rawStats.runtimeInfo) {
273-
const stats = {
274-
cpu: rawStats.runtimeInfo.cpu,
275-
timestamp: rawStats.runtimeInfo.timestamp,
276-
}
277-
278-
updateRegistry(
279-
tsServer,
280-
Object.assign(
281-
{
282-
stats,
283-
},
284-
info
285-
)
286-
)
287-
}
288-
289-
if (rawStats.pgInfo) {
290-
const stats = {
291-
cpu: rawStats.runtimeInfo.cpu,
292-
memory: rawStats.runtimeInfo.cpu,
293-
timestamp: rawStats.runtimeInfo.timestamp,
294-
tableMeta: rawStats.pgInfo,
295-
}
296-
297-
updateTimeseriesRegistry(
298-
tsServer,
299-
Object.assign(
300-
{
301-
stats,
302-
},
303-
info
304-
)
305-
)
306-
}
307-
})
308-
309-
return db
310-
}
311-
312-
// TODO: extract timeseries stuff out, we don't really need it for 99.99% of tests
313217
export async function start(opts: Options) {
314218
const parsedOpts = await resolveOpts(opts)
315219

@@ -342,132 +246,6 @@ export async function start(opts: Options) {
342246
},
343247
})
344248

345-
// const tsRegistry = await startTimeseriesRegistry({
346-
// registry: {
347-
// port: parsedOpts.port,
348-
// host: parsedOpts.host,
349-
// },
350-
// })
351-
352-
// const timeseriesPostgres = await startTimeseries({
353-
// registry: {
354-
// port: parsedOpts.port,
355-
// host: parsedOpts.host,
356-
// },
357-
// // TODO: make port configurable
358-
// port: 5436,
359-
// })
360-
361-
// const timeseries = await startTimeseriesQueue({
362-
// registry,
363-
// // @ts-ignore
364-
// dir: opts.dir,
365-
// pipeRedisLogs: parsedOpts.pipeRedisLogs || {
366-
// stdout: true,
367-
// stderr: true,
368-
// },
369-
// })
370-
//
371-
// const timeseriesWorker = await startTimeseriesWorker({
372-
// registry: {
373-
// port: parsedOpts.port,
374-
// host: parsedOpts.host,
375-
// },
376-
// })
377-
378-
const subs = await startSubscriptionManager({
379-
registry: {
380-
port: parsedOpts.port,
381-
host: parsedOpts.host,
382-
},
383-
})
384-
385-
const subsRegistry = await startSubscriptionRegistry({
386-
registry: {
387-
port: parsedOpts.port,
388-
host: parsedOpts.host,
389-
},
390-
})
391-
392-
registry.on('close', async () => {
393-
// TODO: Remove comment
394-
await origin.destroy()
395-
await subs.destroy()
396-
await subsRegistry.destroy()
397-
// await timeseries.destroy()
398-
// await tsRegistry.destroy()
399-
// timeseriesPostgres.destroy() // not async
400-
// await timeseriesWorker.destroy()
401-
})
402-
403-
return registry
404-
}
405-
406-
export async function startWithTimeseries(opts: Options) {
407-
const parsedOpts = await resolveOpts(opts)
408-
409-
// TODO: for now all in different ports, fix later
410-
const err = validate(
411-
parsedOpts,
412-
[],
413-
['registry', 'backups', 'name', 'default']
414-
)
415-
416-
if (err) {
417-
console.error(`Error starting selva server ${chalk.red(err)}`)
418-
throw new Error(err)
419-
}
420-
421-
const registry = await startServer('registry', {
422-
...parsedOpts,
423-
name: 'registry',
424-
})
425-
426-
const origin = await startOrigin({
427-
name: 'default',
428-
registry,
429-
// @ts-ignore
430-
dir: opts.dir,
431-
selvaOptions: parsedOpts.selvaOptions,
432-
pipeRedisLogs: parsedOpts.pipeRedisLogs || {
433-
stdout: true,
434-
stderr: true,
435-
},
436-
})
437-
438-
const tsRegistry = await startTimeseriesRegistry({
439-
registry: {
440-
port: parsedOpts.port,
441-
host: parsedOpts.host,
442-
},
443-
})
444-
445-
const timeseriesPostgres = await startTimeseries({
446-
registry: {
447-
port: parsedOpts.port,
448-
host: parsedOpts.host,
449-
},
450-
// TODO: make port configurable
451-
port: 5436,
452-
})
453-
454-
const timeseries = await startTimeseriesQueue({
455-
registry,
456-
// @ts-ignore
457-
dir: opts.dir,
458-
pipeRedisLogs: parsedOpts.pipeRedisLogs || {
459-
stdout: true,
460-
stderr: true,
461-
},
462-
})
463-
464-
const timeseriesWorker = await startTimeseriesWorker({
465-
registry: {
466-
port: parsedOpts.port,
467-
host: parsedOpts.host,
468-
},
469-
})
470-
471249
const subs = await startSubscriptionManager({
472250
registry: {
473251
port: parsedOpts.port,
@@ -484,14 +262,9 @@ export async function startWithTimeseries(opts: Options) {
484262

485263
registry.on('close', async () => {
486264
// TODO: Remove comment
487-
// console.log('Close all servers does it work ?')
488265
await origin.destroy()
489266
await subs.destroy()
490267
await subsRegistry.destroy()
491-
await timeseries.destroy()
492-
await tsRegistry.destroy()
493-
timeseriesPostgres.destroy() // not async
494-
await timeseriesWorker.destroy()
495268
})
496269

497270
return registry

server/src/server/timeseriesWorker/index.ts

-64
This file was deleted.

0 commit comments

Comments
 (0)