Skip to content

Commit

Permalink
fix: handle job failure
Browse files Browse the repository at this point in the history
  • Loading branch information
pociej committed May 9, 2024
1 parent f87dc76 commit bacaa88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/src/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { paymentService } from "./services/payment/index.js";
import { fileService } from "./services/file/service.js";
import * as GolemSDK from "@golem-sdk/task-executor";
import { Yagna } from "./services/yagna/service.js";
import { TaskExecutor } from "@golem-sdk/task-executor";

export const container = awilix.createContainer<{
db: Promise<typeof mongoose>;
userService: typeof userService;
Expand Down
24 changes: 15 additions & 9 deletions backend/src/services/file/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ export const fileService = (
//TODO handle errors and timeouts
//but it seems that there was no try to find another one
//this is task executor abstraction so it should handle it for me
const results = await worker.context
?.beginBatch()
.uploadFile(`${DIR_NAME}${fileName}`, `/golem/workdir/${fileName}`)
.run(`/golem/scripts/clamscan-json.sh /golem/workdir/${fileName}`)
.run("ls /golem/output/")
.run(`cat /golem/output/temp/metadata.json`)
.end();
try {
const results = await worker.context
?.beginBatch()
.uploadFile(`${DIR_NAME}${fileName}`, `/golem/workdir/${fileName}`)
.run(`/golem/scripts/clamscan-json.sh /golem/workdir/${fileName}`)
.run("ls /golem/output/")
.run(`cat /golem/output/temp/metadata.json`)
.end();

//@ts-ignore
return JSON.parse((results[3].stdout || "null") as string);
} catch(err) {
debugLog("file","Error scannin file", err);
return null;
}

//@ts-ignore
return JSON.parse((results[3].stdout || "null") as string);
},
async processFile(fileName: string, userId: string) {
debugLog("file", "Processing file", fileName);
Expand Down

0 comments on commit bacaa88

Please sign in to comment.