MCPcopy Create free account
hub / github.com/esmBot/esmBot / acceptJob

Function acceptJob

src/api/index.ts:97–128  ·  view source on GitHub ↗

* Accept a media job.

(id: bigint, sock: WSocket)

Source from the content-addressed store, hash-verified

95 * Accept a media job.
96 */
97async function acceptJob(id: bigint, sock: WSocket): Promise<void> {
98 const job = jobs.get(id)!;
99 try {
100 await runJob(
101 {
102 id: id,
103 msg: job.msg,
104 num: job.num,
105 },
106 sock,
107 );
108 log(`Job ${id} has finished`);
109 } catch (err) {
110 if (!(err instanceof Error)) return;
111 error(`Error on job ${id}: ${err}`, job.num);
112 const newJob = jobs.get(id)!;
113 if (!newJob.tag) {
114 newJob.error = err.message;
115 jobs.set(id, newJob);
116 return;
117 }
118 jobs.delete(id);
119 sock.send(Buffer.concat([Buffer.from([Rerror]), newJob.tag, Buffer.from(err.message)]));
120 }
121
122 // Because malloc_trim can sometimes take longer than expected,
123 // we wait until all* jobs are finished before trimming to avoid potential issues.
124 // See the comment in natives/node/media.cc for more info
125 if (jobs.size <= 1) {
126 media.trim();
127 }
128}
129
130function waitForVerify(event: EventEmitter<VerifyEvents>): Promise<Buffer> {
131 return new Promise((resolve, reject) => {

Callers 1

index.tsFile · 0.85

Calls 6

runJobFunction · 0.85
trimMethod · 0.80
logFunction · 0.70
errorFunction · 0.70
setMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected