improved database updates for assignment creation
This commit is contained in:
parent
fd993102a0
commit
e2d728265b
8 changed files with 211 additions and 92 deletions
|
|
@ -91,13 +91,6 @@ app.post("/deploy", async (req, res) => {
|
|||
return res.status(400).json({ error: "appName required" });
|
||||
}
|
||||
|
||||
// const notebookPath = path.join(__dirname, '../snakeapi_service/notebooks', notebookName);
|
||||
// console.log('Resolved notebookPath:', notebookPath);
|
||||
// if (!fs.existsSync(notebookPath)) {
|
||||
// console.error('Notebook not found at:', notebookPath);
|
||||
// return res.status(500).json({ error: `Notebook not found: ${notebookPath}` });
|
||||
// }
|
||||
|
||||
try {
|
||||
const fly = createFlyClient();
|
||||
|
||||
|
|
@ -108,17 +101,6 @@ app.post("/deploy", async (req, res) => {
|
|||
primary_region: "sea",
|
||||
});
|
||||
|
||||
// console.log('Uploading notebook to S3');
|
||||
// const data = fs.readFileSync(notebookPath);
|
||||
// const key = `${appName}/notebooks/${Date.now()}-notebook.ipynb`;
|
||||
// console.log('S3 key:', key);
|
||||
// await s3.putObject({
|
||||
// Bucket: COMMON_BUCKET,
|
||||
// Key: key,
|
||||
// Body: data,
|
||||
// ContentType: 'application/json'
|
||||
// }).promise();
|
||||
|
||||
console.log("Creating machine");
|
||||
const machineConfig = {
|
||||
name: `${appName}-machine`,
|
||||
|
|
@ -237,12 +219,23 @@ app.post("/:appName/delete", async (req, res) => {
|
|||
try {
|
||||
const fly = createFlyClient();
|
||||
console.log("Destroying Fly app:", appName);
|
||||
|
||||
//check if the app exists
|
||||
console.log("Checking if app exists:", appName);
|
||||
const appCheck = await fly.get(`/apps/${appName}`);
|
||||
console.log("App check response:", appCheck.status);
|
||||
if (appCheck.status !== 200) {
|
||||
console.log("App not found:", appName);
|
||||
return res.json({ status: "App not found", app: appName });
|
||||
}
|
||||
|
||||
await fly.delete(`/apps/${appName}`);
|
||||
|
||||
return res.json({ status: "deleted", app: appName });
|
||||
} catch (err) {
|
||||
console.error("App deletion error:", err.response?.data || err.message);
|
||||
return res.status(500).json({ error: err.response?.data || err.message });
|
||||
const errorData = err.response?.data || err.stack || err.message;
|
||||
console.error("App deletion error:", errorData);
|
||||
return res.status(500).json({ errorData });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -250,3 +243,28 @@ const LISTEN_PORT = process.env.PORT || 3006;
|
|||
app.listen(LISTEN_PORT, "0.0.0.0", () => {
|
||||
console.log(`Deployment service listening on port ${LISTEN_PORT}`);
|
||||
});
|
||||
|
||||
//deploy fly app based on appname
|
||||
app.post("/deploy/:appName", async (req, res) => {
|
||||
const { appName } = req.params;
|
||||
const { region } = req.body;
|
||||
|
||||
if (!appName || !region) {
|
||||
return res.status(400).json({ error: "appName and region are required" });
|
||||
}
|
||||
|
||||
try {
|
||||
const fly = createFlyClient();
|
||||
console.log("Creating Fly app:", appName);
|
||||
await fly.post("/apps", {
|
||||
app_name: appName,
|
||||
org_slug: FLY_ORG,
|
||||
primary_region: region,
|
||||
});
|
||||
|
||||
return res.json({ status: "created", app: appName });
|
||||
} catch (err) {
|
||||
console.error("App creation error:", err.response?.data || err.message);
|
||||
return res.status(500).json({ error: err.response?.data || err.message });
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue