Skip to content

Commit

Permalink
Remove ps-node and just poll the http listener
Browse files Browse the repository at this point in the history
ps-node has an issue (neekey/ps#79) and
appears to have been abandoned

This checks that the project id returned from /flowforge/info endpoint
is consitent with the expect id
  • Loading branch information
hardillb committed Mar 8, 2022
1 parent d069222 commit 01bab0f
Showing 1 changed file with 26 additions and 101 deletions.
127 changes: 26 additions & 101 deletions localfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

const fs = require('fs')
const ps = require('ps-node')
// const ps = require('ps-node')
const got = require('got')
const path = require('path')
const childProcess = require('child_process')
Expand Down Expand Up @@ -118,8 +118,6 @@ async function startProject (app, project, options, userDir, port) {
app.config.base_url,
'--project',
project.id
// '--token',
// options.projectToken
]

const proc = childProcess.spawn(execPath, args, processOptions)
Expand All @@ -137,59 +135,33 @@ function checkExistingProjects (driver, projects) {
createUserDirIfNeeded(driver._rootDir, project.id)

const localProjects = driver._projects
ps.lookup({ pid: projectSettings.pid }, async function (err, results) {
if (!err) {
if (!results[0]) {
// let projectOpts = JSON.parse(project.options)
logger.info(`restating ${project.id}}`)
if (projectSettings.path && projectSettings.port) {
const pid = await startProject(driver._app, project, {}, projectSettings.path, projectSettings.port)
if (!driver._usedPorts.includes(projectSettings.port)) {
driver._usedPorts.push(projectSettings.port)
}
await project.updateSetting('pid', pid)
localProjects[project.id] = {
process: pid,
dir: project.path,
port: project.port,
state: 'running'
}
} else {
logger.info(`missing port or path for ${project.id}`)
}
} else {
// found
logger.debug(`found ${results[0].pid}`)
if (results[0].arguments.includes('--forgeURL') && results[0].arguments.includes(project.id)) {
// should maybe hit the /flowforge/info endpoint
localProjects[project.id] = {
process: projectSettings.pid,
dir: projectSettings.path,
port: projectSettings.port,
state: 'running'
}
} else {
logger.info("matching pid, but doesn't match project id, restarting")
if (projectSettings.path && projectSettings.port) {
if (!driver._usedPorts.includes(projectSettings.port)) {
driver._usedPorts.push(projectSettings.port)
}
// should restart
const pid = await startProject(driver._app, project, {}, projectSettings.path, projectSettings.port)
await project.updateSetting('pid', pid)
localProjects[project.id] = {
process: pid,
dir: project.path,
port: project.port,
state: 'running'
}
} else {
logger.info(`missing port or path for ${project.id}`)
}
}

try {
const info = await got.get(`http://localhost:${projectSettings.port + 1000}/flowforge/info`, {
timeout: {
request: 1000
}
})
console.log(info)
if (project.id !== info.id) {
// Running project doesn't match db
logger.info('Project on port projectSettings.port does not match database')
}
})
} catch (err) {
// console.log(`Error: ${err}`)
logger.info(`restarting ${project.id}}`)
const pid = await startProject(driver._app, project, {}, projectSettings.path, projectSettings.port)
if (!driver._usedPorts.includes(projectSettings.port)) {
driver._usedPorts.push(projectSettings.port)
}
await project.updateSetting('pid', pid)
localProjects[project.id] = {
process: pid,
dir: project.path,
port: project.port,
state: 'running'
}
}
})
}

Expand Down Expand Up @@ -227,53 +199,6 @@ module.exports = {
checkExistingProjects(driver, projects)
}, 60000)

// projects.forEach(async (project) => {
// const projectSettings = await project.getAllSettings();
// this._usedPorts.push(projectSettings.port)
// createUserDirIfNeeded(this._rootDir, project.id)

// let localProjects = this._projects
// ps.lookup({pid: projectSettings.pid}, async function(err, results){
// if (!err) {
// if (!results[0]) {
// // let projectOpts = JSON.parse(project.options)
// let pid = await startProject(project, {}, projectSettings.path, projectSettings.port);
// await project.updateSetting('pid',pid);
// localProjects[project.id] = {
// process: pid,
// dir: project.path,
// port: project.port,
// state: "running"
// }
// } else {
// //found
// console.log("found", results[0])
// if (results[0].arguments.includes('--forgeURL') &&
// results[0].arguments.includes(project.id)) {
// //should maybe hit the /flowforge/info endpoint
// localProjects[project.id] = {
// process: projectSettings.pid,
// dir: projectSettings.path,
// port: projectSettings.port,
// state: "running"
// }
// } else {
// console.log("matching pid, but doesn't match project id")
// //should restart
// let pid = await startProject(project, {}, projectSettings.path, projectSettings.port);
// await project.updateSetting('pid',pid);
// localProjects[project.id] = {
// process: pid,
// dir: project.path,
// port: project.port,
// state: "running"
// }
// }
// }
// }
// })
// })

// nothing to expose at the moment
return {}
},
Expand Down

0 comments on commit 01bab0f

Please sign in to comment.