Skip to content

Commit

Permalink
Fix dangling process issues
Browse files Browse the repository at this point in the history
  • Loading branch information
snowteamer committed Aug 29, 2022
1 parent 6f5bbae commit 3bdba00
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
73 changes: 44 additions & 29 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,35 @@ module.exports = (grunt) => {
cypress[command](options).then(r => done(r.totalFailed === 0)).catch(done)
})

grunt.registerTask('deno', function () {
grunt.registerTask('pin', async function (version) {
if (typeof version !== 'string') throw new Error('usage: grunt pin:<version>')
const done = this.async()
const dirPath = `contracts/${version}`

if (fs.existsSync(dirPath)) {
if (grunt.option('overwrite')) { // if the task is run with '--overwrite' option, empty the folder first.
fs.rmSync(dirPath, { recursive: true })
} else {
throw new Error(`already exists: ${dirPath}`)
}
}
// since the copied manifest files might not have the correct version on them
// we need to delete the old ones and regenerate them
await execWithErrMsg(`rm -f ${distContracts}/*.manifest.json`)
await genManifestsAndDeploy(distContracts, version)
await execWithErrMsg(`cp -r ${distContracts} ${dirPath}`, 'error copying contracts')
console.log(chalk`{green Version} {bold ${version}} {green pinned to:} ${dirPath}`)
// it's possible for the UI to get updated without the contracts getting updated,
// so we keep their version numbers separate.
packageJSON.contractsVersion = version
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2) + '\n', 'utf8')
console.log(chalk.green('updated package.json "contractsVersion" to:'), version)
done()
})

grunt.registerTask('default', ['dev'])

grunt.registerTask('deno:start', function () {
const done = this.async() // Tell Grunt we're async.
const fork2 = function () {
grunt.log.writeln('backend: forking...')
Expand Down Expand Up @@ -456,35 +484,15 @@ module.exports = (grunt) => {
}
})

grunt.registerTask('pin', async function (version) {
if (typeof version !== 'string') throw new Error('usage: grunt pin:<version>')
const done = this.async()
const dirPath = `contracts/${version}`

if (fs.existsSync(dirPath)) {
if (grunt.option('overwrite')) { // if the task is run with '--overwrite' option, empty the folder first.
fs.rmSync(dirPath, { recursive: true })
} else {
throw new Error(`already exists: ${dirPath}`)
}
grunt.registerTask('deno:stop', function () {
if (child) {
grunt.log.writeln('Quitting dangling child!')
child.kill()
}
// since the copied manifest files might not have the correct version on them
// we need to delete the old ones and regenerate them
await execWithErrMsg(`rm -f ${distContracts}/*.manifest.json`)
await genManifestsAndDeploy(distContracts, version)
await execWithErrMsg(`cp -r ${distContracts} ${dirPath}`, 'error copying contracts')
console.log(chalk`{green Version} {bold ${version}} {green pinned to:} ${dirPath}`)
// it's possible for the UI to get updated without the contracts getting updated,
// so we keep their version numbers separate.
packageJSON.contractsVersion = version
fs.writeFileSync('package.json', JSON.stringify(packageJSON, null, 2) + '\n', 'utf8')
console.log(chalk.green('updated package.json "contractsVersion" to:'), version)
done()
})

grunt.registerTask('default', ['dev'])
// TODO: add 'deploy' as per https://github.com/okTurtles/group-income/issues/10
grunt.registerTask('dev', ['checkDependencies', 'exec:chelDeployAll', 'build:watch', 'deno', 'keepalive'])
grunt.registerTask('dev', ['checkDependencies', 'exec:chelDeployAll', 'build:watch', 'deno:start', 'keepalive'])
grunt.registerTask('dist', ['build'])

// --------------------
Expand Down Expand Up @@ -548,7 +556,7 @@ module.exports = (grunt) => {

;[
[['Gruntfile.js'], [eslint]],
[['backend/**/*.ts', 'shared/**/*.js'], [eslint, 'deno']],
[['backend/**/*.ts', 'shared/**/*.js'], [eslint, 'deno:start']],
[['frontend/**/*.html'], ['copy']],
[['frontend/**/*.js'], [eslint]],
[['frontend/assets/{fonts,images}/**/*'], ['copy']],
Expand Down Expand Up @@ -621,6 +629,12 @@ module.exports = (grunt) => {
done()
})

// Stops the Flowtype server.
grunt.registerTask('flow:stop', function () {
grunt.log.writeln('Stopping Flowtype server')
exec('./node_modules/.bin/flow stop')
})

// eslint-disable-next-line no-unused-vars
let killKeepAlive = null
grunt.registerTask('keepalive', function () {
Expand All @@ -629,14 +643,15 @@ module.exports = (grunt) => {
killKeepAlive = this.async()
})

grunt.registerTask('test', ['build', 'exec:chelDeployAll', 'deno', 'exec:test', 'cypress'])
grunt.registerTask('test:unit', ['deno', 'exec:test'])
grunt.registerTask('test', ['build', 'exec:chelDeployAll', 'deno:start', 'exec:test', 'cypress', 'deno:stop', 'flow:stop'])
grunt.registerTask('test:unit', ['deno:start', 'exec:test', 'deno:stop'])

// -------------------------------------------------------------------------
// Process event handlers
// -------------------------------------------------------------------------

process.on('exit', () => {
console.log('exiting...')
// Note: 'beforeExit' doesn't work.
// In cases where 'watch' fails while child (server) is still running
// we will exit and child will continue running in the background.
Expand Down
4 changes: 1 addition & 3 deletions backend/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ route.GET('/file/{hash}', async function handler (request, h) {
route.GET('/assets/{subpath*}', async function handler (request, h) {
try {
const { subpath } = request.params
console.log('subpath:', subpath)
const basename = pathlib.basename(subpath)
console.debug(`GET /assets/${subpath}`)
const basename = pathlib.basename(subpath)
const base = pathlib.resolve('dist/assets')
console.log('base:', base)
// In the build config we told our bundler to use the `[name]-[hash]-cached` template
// to name immutable assets. This is useful because `dist/assets/` currently includes
// a few files without hash in their name.
Expand Down

0 comments on commit 3bdba00

Please sign in to comment.