Skip to content

Commit 7b7007c

Browse files
committed
chore: Added comments to code
1 parent fa1a086 commit 7b7007c

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

express_backend/code/generateFile.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ if (!fs.existsSync(dirCodes)) {
99
}
1010

1111
const generateFile = async (format, content) => {
12+
13+
// generating random id
1214
const jobId = uuid();
15+
16+
// generating name of the file
1317
const filename = `${jobId}.${format}`;
18+
19+
// fetching file name
1420
const filepath = path.join(dirCodes, filename);
15-
await fs.writeFileSync(filepath, content);
21+
22+
// write incoming on the file
23+
fs.writeFileSync(filepath, content);
24+
1625
return filepath;
1726
};
1827

express_backend/code/job_queue_playground.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,51 @@ const NUM_WORKERS = 5;
88

99
jobQueuePlayground.process(NUM_WORKERS, async ({ data }) => {
1010
const jobId = data.id;
11+
12+
// finding the job with id of the job
1113
const job = await jobs.findById(jobId);
14+
15+
// if job not found, throw error
1216
if (job === undefined) {
1317
throw Error(`cannot find Job with id ${jobId}`);
1418
}
15-
console.log("data", data)
19+
20+
1621
try {
17-
console.log("Inside try block of jobQueue of playground")
22+
1823
let output;
24+
25+
// writing started at time
1926
job["startedAt"] = new Date();
27+
28+
//
2029
if (job.language === "cpp") {
30+
31+
// executing code for C++
2132
output = await executeCpp(job.filepath, data.inputs);
33+
2234
} else if (job.language === "py") {
23-
console.log("Inside python block")
35+
36+
// executing code for python
2437
output = await executePy(job.filepath, data.inputs);
2538
}
39+
2640
job["completedAt"] = new Date();
41+
42+
// setting up the output generated by the code
2743
job["output"] = output;
44+
45+
// output generated -> success, job executed successfully
46+
// doesn't matter if code contains error
47+
// it just shows, wheather code entered executed correctly
48+
// or not
2849
job["status"] = "success";
50+
51+
// saving the job
2952
await job.save();
53+
3054
return true;
55+
3156
} catch (err) {
3257
job["completedAt"] = new Date();
3358
job["output"] = JSON.stringify(err);

0 commit comments

Comments
 (0)