Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: non flushed io #22

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ your workflow, allowing you to reuse them for faster consecutive runs.
## Prerequisites

- Supported Platforms: WarpBuild Linux x64 and arm runners.
- Unsupported Platforms: BYOC based runners, container image based runners and Mac runners are not
supported.
- Unsupported Platforms: BYOC based runners, container image based runners and
Mac runners are not supported.

## Usage

Expand Down Expand Up @@ -178,4 +178,4 @@ This project is licensed under the [MIT License](LICENSE).

## Addtional Notes

BYOC based snapshot runners will be launched soon.
BYOC based snapshot runners will be launched soon.
51 changes: 40 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

56 changes: 44 additions & 12 deletions src/snapshotter/snapshotter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Logger } from './logger'
import { Warpbuild, WarpbuildOptions } from './warpbuild-client'
import { humanTime } from './human-time'
import { CommonsRunnerImageVersion } from '../warpbuild/src'
import { exec } from 'child_process'
import { spawn } from 'child_process'
import * as fs from 'fs'

export type SnapshotterOptions = {
Expand Down Expand Up @@ -74,6 +74,13 @@ set -e
# Remove /var/lib/warpbuild-agentd/settings.json
sudo rm /var/lib/warpbuild-agentd/settings.json

# This command forces a write of all buffered I/O data to the disks.
echo "Flushing file system buffers..."
sync

# Pause for a few seconds to ensure all I/O operations are complete
# sleep 5

echo "Cleanup complete"
`

Expand All @@ -82,17 +89,42 @@ echo "Cleanup complete"
fs.chmodSync(cleanupScriptFile, '755')
this.logger.debug(`Cleanup script: ${cleanupScriptFile}`)

exec(`bash ./${cleanupScriptFile}`, (error, stdout, stderr) => {
if (error) {
this.logger.error(error.message)
return
}
if (stderr) {
this.logger.error(stderr)
return
}
this.logger.debug(stdout)
})
// Check if the file exists and has the correct permissions
try {
fs.accessSync(cleanupScriptFile, fs.constants.X_OK)
this.logger.debug(`${cleanupScriptFile} is executable.`)
} catch (err) {
this.logger.error(
`${cleanupScriptFile} is not executable or not found: ${err}`
)
return
}

try {
// Use spawn instead of exec for better control over output
const cleanupProcess = spawn(`bash`, [`./${cleanupScriptFile}`], {
stdio: 'inherit' // Use 'inherit' to show the output directly
})

cleanupProcess.on('error', error => {
this.logger.error(`Failed to start cleanup script: ${error.message}`)
})

cleanupProcess.on('exit', code => {
if (code === 0) {
this.logger.info('Cleanup script executed successfully.')
} else {
this.logger.error(`Cleanup script exited with code ${code}`)
}
})

// Wait for the cleanup process to finish before proceeding
await new Promise(resolve => {
cleanupProcess.on('close', resolve)
})
} catch (err) {
this.logger.error(`Error running cleanup script: ${err}`)
}

const warpbuildClient = new Warpbuild(wo)

Expand Down
Loading