20 lines
623 B
JavaScript
20 lines
623 B
JavaScript
import process from 'node:process';
|
|
|
|
import { knexOwner as knex } from '../src/knex.js';
|
|
import redis from '../src/redis.js';
|
|
|
|
// runs a command line tool and closes the connections afterwards, the knex pool and redis would otherwise keep the process alive
|
|
export default async function runTool(tool) {
|
|
try {
|
|
await tool();
|
|
|
|
await knex.destroy();
|
|
await redis.quit();
|
|
}
|
|
catch (error) {
|
|
// the manticore client rejects with a plain response object rather than an Error, print the server's message
|
|
console.error(error instanceof Error ? error : error?.body?.error || error?.body || error);
|
|
process.exit(1);
|
|
}
|
|
}
|