Skip to content

Commit

Permalink
work on integrating DB with action server
Browse files Browse the repository at this point in the history
  • Loading branch information
dandelany committed Mar 5, 2025
1 parent 103d06b commit f920b16
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions action-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,41 @@ async function handleActionRun(payload: ActionRunInsertedPayload) {
} as ActionResponse;
console.log('finished run');
console.log(response);

const status = jsRun.errors ? "failed" : "success";

const logStr: string = [ // todo replace this with proper log stringification
jsRun.console.error.join('\n'),
jsRun.console.warn.join('\n'),
jsRun.console.log.join('\n'),
jsRun.console.info.join('\n'),
jsRun.console.debug.join('\n')
].join('\n');

const pool = ActionsDbManager.getDb();
const query = `
UPDATE actions.action_run
SET
status = $1,
error = $2::jsonb,
results = $3::jsonb,
logs = $4,
WHERE id = $5
RETURNING *;
`;

try {
const res = await pool.query(query, [
status,
JSON.stringify(jsRun.errors),
JSON.stringify(jsRun.results),
logStr
]);
console.log("Updated action_run:", res.rows[0]);
} catch (err) {
console.error("Error updating row:", err);
}

}

let pool: Pool | undefined;
Expand Down

0 comments on commit f920b16

Please sign in to comment.