@platformatic/control 2.74.3 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/logs.js DELETED
@@ -1,67 +0,0 @@
1
- 'use strict'
2
-
3
- const { parseArgs } = require('node:util')
4
- const { prettyFactory } = require('pino-pretty')
5
- const RuntimeApiClient = require('./runtime-api-client')
6
-
7
- const pinoLogLevels = {
8
- fatal: 60,
9
- error: 50,
10
- warn: 40,
11
- info: 30,
12
- debug: 20,
13
- trace: 10,
14
- }
15
-
16
- async function streamRuntimeLogsCommand (argv) {
17
- const args = parseArgs({
18
- args: argv,
19
- options: {
20
- pid: { type: 'string', short: 'p' },
21
- name: { type: 'string', short: 'n' },
22
- level: { type: 'string', short: 'l', default: 'info' },
23
- pretty: { type: 'string', default: 'true' },
24
- service: { type: 'string', short: 's' },
25
- },
26
- strict: false,
27
- }).values
28
-
29
- const client = new RuntimeApiClient()
30
- const runtime = await client.getMatchingRuntime(args)
31
-
32
- const logLevelNumber = pinoLogLevels[args.level]
33
- const prettify = prettyFactory()
34
-
35
- const logsStream = client.getRuntimeLiveLogsStream(runtime.pid)
36
-
37
- logsStream.on('data', (data) => {
38
- const logs = data.toString().split('\n').filter(Boolean)
39
-
40
- for (let log of logs) {
41
- try {
42
- const parsedLog = JSON.parse(log)
43
- if (parsedLog.level < logLevelNumber) continue
44
- if (args.service && parsedLog.name !== args.service) continue
45
- if (args.pretty !== 'false') {
46
- log = prettify(parsedLog)
47
- } else {
48
- log += '\n'
49
- }
50
- process.stdout.write(log)
51
- } catch (err) {
52
- console.error('Failed to parse log message: ', log, err)
53
- }
54
- }
55
- })
56
-
57
- process.on('SIGINT', () => {
58
- logsStream.destroy()
59
- process.exit(0)
60
- })
61
- process.on('SIGTERM', () => {
62
- logsStream.destroy()
63
- process.exit(0)
64
- })
65
- }
66
-
67
- module.exports = streamRuntimeLogsCommand
package/lib/metrics.js DELETED
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- const { parseArgs } = require('node:util')
4
-
5
- const RuntimeApiClient = require('./runtime-api-client')
6
-
7
- async function runtimeMetricsCommand (argv) {
8
- const args = parseArgs({
9
- args: argv,
10
- options: {
11
- pid: { type: 'string', short: 'p' },
12
- format: { type: 'string', short: 'f', default: 'json' }
13
- },
14
- strict: false,
15
- }).values
16
-
17
- const client = new RuntimeApiClient()
18
- const runtimePid = args.pid || (await client.getMatchingRuntime([])).pid
19
- const metrics = await client.getRuntimeMetrics(parseInt(runtimePid), { format: args.format })
20
- const result = args.format === 'text' ? metrics : JSON.stringify(metrics, null, 2)
21
- console.log(result)
22
- await client.close()
23
- }
24
-
25
- module.exports = runtimeMetricsCommand
package/lib/ps.js DELETED
@@ -1,96 +0,0 @@
1
- 'use strict'
2
-
3
- const { table, getBorderCharacters } = require('table')
4
- const RuntimeApiClient = require('./runtime-api-client')
5
-
6
- const tableColumns = [
7
- {
8
- value: 'pid',
9
- alias: 'PID',
10
- },
11
- {
12
- value: 'packageName',
13
- alias: 'NAME',
14
- },
15
- {
16
- value: 'platformaticVersion',
17
- alias: 'PLT',
18
- },
19
- {
20
- value: 'uptimeSeconds',
21
- alias: 'TIME',
22
- formatter: formatRuntimeTime,
23
- },
24
- {
25
- value: 'url',
26
- alias: 'URL',
27
- },
28
- {
29
- value: 'projectDir',
30
- alias: 'PWD',
31
- },
32
- ]
33
-
34
- function formatRuntimeTime (timeSeconds) {
35
- let result = ''
36
- if (timeSeconds < 3600) {
37
- const seconds = Math.floor(timeSeconds % 60)
38
- result = `${seconds}s`
39
- }
40
- if (timeSeconds >= 60) {
41
- const minutes = Math.floor((timeSeconds % 3600) / 60)
42
- result = `${minutes}m ` + result
43
- }
44
- if (timeSeconds >= 3600) {
45
- const hours = Math.floor((timeSeconds % (3600 * 24)) / 3600)
46
- result = `${hours}h ` + result
47
- }
48
- if (timeSeconds >= 3600 * 24) {
49
- const days = Math.floor(timeSeconds / (3600 * 24))
50
- result = `${days}d ` + result
51
- }
52
- return result
53
- }
54
-
55
- const tableConfig = {
56
- border: getBorderCharacters('void'),
57
- columnDefault: {
58
- paddingLeft: 0,
59
- paddingRight: 1,
60
- },
61
- drawHorizontalLine: () => false,
62
- }
63
-
64
- async function printRuntimes (runtimes) {
65
- const raws = [tableColumns.map(column => column.alias)]
66
-
67
- for (const runtime of runtimes) {
68
- const raw = []
69
- for (const column of tableColumns) {
70
- let value = runtime[column.value]
71
- if (column.formatter) {
72
- value = column.formatter(value)
73
- }
74
- value ??= '-----'
75
- raw.push(value)
76
- }
77
- raws.push(raw)
78
- }
79
-
80
- const runtimesTable = table(raws, tableConfig)
81
- process.stdout.write(runtimesTable)
82
- }
83
-
84
- async function listRuntimesCommand () {
85
- const client = new RuntimeApiClient()
86
- const runtimes = await client.getRuntimes()
87
- if (runtimes.length === 0) {
88
- console.log('No platformatic runtimes found.')
89
- return
90
- }
91
- printRuntimes(runtimes)
92
-
93
- await client.close()
94
- }
95
-
96
- module.exports = listRuntimesCommand
package/lib/reload.js DELETED
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- const { parseArgs } = require('node:util')
4
- const RuntimeApiClient = require('./runtime-api-client')
5
-
6
- async function reloadRuntimeCommand (argv) {
7
- const args = parseArgs({
8
- args: argv,
9
- options: {
10
- pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' }
12
- },
13
- strict: false
14
- }).values
15
-
16
- const client = new RuntimeApiClient()
17
- const runtime = await client.getMatchingRuntime(args)
18
-
19
- const child = await client.reloadRuntime(runtime.pid)
20
- console.log(`Reloaded runtime "${runtime.packageName}". The new PID is ${child.pid}.`)
21
-
22
- await client.close()
23
- }
24
-
25
- module.exports = reloadRuntimeCommand
package/lib/restart.js DELETED
@@ -1,32 +0,0 @@
1
- 'use strict'
2
-
3
- const { parseArgs } = require('node:util')
4
- const RuntimeApiClient = require('./runtime-api-client')
5
-
6
- async function restartRuntimeCommand (argv) {
7
- const args = parseArgs({
8
- args: argv,
9
- options: {
10
- pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' },
12
- },
13
- strict: false,
14
- }).values
15
-
16
- const client = new RuntimeApiClient()
17
- const runtime = await client.getMatchingRuntime(args)
18
-
19
- const runtimeProcess = await client.restartRuntime(runtime.pid, { stdio: 'inherit' })
20
-
21
- process.on('SIGINT', () => {
22
- runtimeProcess.kill('SIGINT')
23
- })
24
-
25
- process.on('SIGTERM', () => {
26
- runtimeProcess.kill('SIGTERM')
27
- })
28
-
29
- await client.close()
30
- }
31
-
32
- module.exports = restartRuntimeCommand
package/lib/services.js DELETED
@@ -1,79 +0,0 @@
1
- 'use strict'
2
-
3
- const { parseArgs } = require('node:util')
4
- const { table, getBorderCharacters } = require('table')
5
- const RuntimeApiClient = require('./runtime-api-client')
6
-
7
- const tableColumns = [
8
- {
9
- value: 'id',
10
- alias: 'NAME'
11
- },
12
- {
13
- value: 'workers',
14
- alias: 'WORKERS',
15
- production: true
16
- },
17
- {
18
- value: 'type',
19
- alias: 'TYPE'
20
- },
21
- {
22
- value: 'entrypoint',
23
- alias: 'ENTRYPOINT',
24
- formatter: entrypoint => {
25
- return entrypoint ? 'yes' : 'no'
26
- }
27
- }
28
- ]
29
-
30
- const tableConfig = {
31
- border: getBorderCharacters('void'),
32
- columnDefault: {
33
- paddingLeft: 0,
34
- paddingRight: 1
35
- },
36
- drawHorizontalLine: () => false
37
- }
38
-
39
- async function printRuntimeServices ({ production, services }) {
40
- const columns = tableColumns.filter(c => typeof c.production === 'undefined' || c.production === production)
41
- const raws = [columns.map(column => column.alias)]
42
-
43
- for (const service of services) {
44
- const raw = []
45
- for (const column of columns) {
46
- let value = service[column.value]
47
- if (column.formatter) {
48
- value = column.formatter(value)
49
- }
50
- value ??= '-----'
51
- raw.push(value)
52
- }
53
- raws.push(raw)
54
- }
55
-
56
- const servicesTable = table(raws, tableConfig)
57
- process.stdout.write(servicesTable)
58
- }
59
-
60
- async function getRuntimeServicesCommand (argv) {
61
- const args = parseArgs({
62
- args: argv,
63
- options: {
64
- pid: { type: 'string', short: 'p' },
65
- name: { type: 'string', short: 'n' }
66
- },
67
- strict: false
68
- }).values
69
-
70
- const client = new RuntimeApiClient()
71
- const runtime = await client.getMatchingRuntime(args)
72
-
73
- const runtimeServices = await client.getRuntimeServices(runtime.pid)
74
- printRuntimeServices(runtimeServices)
75
-
76
- await client.close()
77
- }
78
-
79
- module.exports = getRuntimeServicesCommand
package/lib/stop.js DELETED
@@ -1,25 +0,0 @@
1
- 'use strict'
2
-
3
- const { parseArgs } = require('node:util')
4
- const RuntimeApiClient = require('./runtime-api-client')
5
-
6
- async function stopRuntimeCommand (argv) {
7
- const args = parseArgs({
8
- args: argv,
9
- options: {
10
- pid: { type: 'string', short: 'p' },
11
- name: { type: 'string', short: 'n' },
12
- },
13
- strict: false,
14
- }).values
15
-
16
- const client = new RuntimeApiClient()
17
- const runtime = await client.getMatchingRuntime(args)
18
-
19
- await client.stopRuntime(runtime.pid)
20
- console.log(`Stopped runtime "${runtime.packageName}".`)
21
-
22
- await client.close()
23
- }
24
-
25
- module.exports = stopRuntimeCommand