Skip to content

Commit

Permalink
chore: add try / catch to debug in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Feb 18, 2023
1 parent 98fcd16 commit 56ed9e4
Showing 1 changed file with 47 additions and 40 deletions.
87 changes: 47 additions & 40 deletions src/lib/storage/jobs/helpers/performConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,55 @@ export default async function performConversion({
req,
res,
}: ConversionRequest) {
console.log(`Performing conversion for ${id}`);
const storage = new StorageHandler();
const job = new ConversionJob(DB);
await job.load(id, owner, title);
if (!job.canStart()) {
console.log(`job ${id} was not started`);
return res
? res.status(405).send({ message: 'Job is already active' })
: null;
}
try {
console.log(`Performing conversion for ${id}`);
const storage = new StorageHandler();
const job = new ConversionJob(DB);
await job.load(id, owner, title);
if (!job.canStart()) {
console.log(`job ${id} was not started`);
return res
? res.status(405).send({ message: 'Job is already active' })
: null;
}

console.log(`job ${id} is not active, starting`);
await job.start();
console.log(`job ${id} is not active, starting`);
await job.start();

if (res) {
res.status(200).send();
}
if (res) {
res.status(200).send();
}

const { ws, exporter, settings, bl, rules } = await job.createWorkSpace(api);
const decks = await job.createFlashcards(bl, req, id, rules, settings);
if (!decks) {
await job.failed();
return;
const { ws, exporter, settings, bl, rules } = await job.createWorkSpace(
api
);
const decks = await job.createFlashcards(bl, req, id, rules, settings);
if (!decks) {
await job.failed();
return;
}
const { size, key, apkg } = await job.buildingDeck(
bl,
exporter,
decks,
ws,
settings,
storage,
id,
owner
);
await notifyUserIfNecessary({
owner,
rules,
db: DB,
size,
key,
id,
apkg,
});
await job.completed();
} catch (error) {
res?.status(400).send('conversion failed.');
console.error(error);
}
const { size, key, apkg } = await job.buildingDeck(
bl,
exporter,
decks,
ws,
settings,
storage,
id,
owner
);
await notifyUserIfNecessary({
owner,
rules,
db: DB,
size,
key,
id,
apkg,
});
await job.completed();
}

0 comments on commit 56ed9e4

Please sign in to comment.