Skip to content

Commit

Permalink
change log mode and memory restart
Browse files Browse the repository at this point in the history
  • Loading branch information
rslucena committed May 13, 2024
1 parent a2d945c commit 1149458
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/commands/exec-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ const worker = process.env.npm_config_worker
const err = new Error('Unable to locate the script, provider, or container for execution.')

if (!worker) {
console.log(err)
console.error(err)
process.exit()
}

const jobs = pm2Workspace.find((configs) => configs.name === worker)
if (!jobs) {
console.log(err)
console.error(err)
process.exit()
}

const command = `tsx watch --env-file=.env -- ${jobs.tsx}`

const child = spawn(command, { stdio: 'inherit', shell: true })

child.on('message', (message) => console.log(message))
child.on('message', (message) => console.warn(message))

child.on('error', (error) => console.error('command error:', error))

Expand Down
10 changes: 5 additions & 5 deletions src/commands/pm2-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function format(args: any, eng: string) {

const list = (engine: 'tsx' | 'node') =>
pm2.list((err, list) => {
if (err) return console.log(err)
if (err) return console.error(err)
console.table(list.map((worker: any) => format(worker, engine)))
})

Expand All @@ -34,17 +34,17 @@ const start = (engine: 'tsx' | 'node', worker: worker) =>

const info = (name: string | undefined, engine: string) =>
pm2.list((err, list) => {
if (err) return console.log(err)
if (err) return console.error(err)
const worker = list.find((worker) => worker.name === name)
if (!worker) return console.log('Unable to locate the worker.')
if (!worker) return console.error('Unable to locate the worker.')
console.table(format(worker, engine))
})

const restart = (name: string | undefined) =>
pm2.list((err, list) => {
if (err) return console.log(err)
if (err) return console.error(err)
const worker = list.find((worker) => worker.name === name)
if (!worker) return console.log('Unable to locate the worker.')
if (!worker) return console.error('Unable to locate the worker.')
pm2.restart(worker.name as string, (err, app) => (err ? console.log(err) : console.table(app)))
})

Expand Down
2 changes: 1 addition & 1 deletion src/commands/pm2-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const defaultConfigs: pm2.StartOptions = {
max_restarts: 5,
exec_mode: 'fork',
autorestart: true,
max_memory_restart: '300M',
max_memory_restart: '100M',
ignore_watch: ['node_modules'],
}

Expand Down

0 comments on commit 1149458

Please sign in to comment.