Skip to content

Commit 7fafa27

Browse files
committed
chore: wip
1 parent 0975c49 commit 7fafa27

8 files changed

Lines changed: 56 additions & 17 deletions

File tree

.vscode/dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
antfu
2+
backoffs
23
biomejs
34
booleanish
5+
bullmq
46
bumpp
57
bunfig
68
bunx

bun.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,11 @@
7474
},
7575
"lint-staged": {
7676
"*.{js,ts}": "bunx --bun eslint . --fix"
77+
},
78+
"dependencies": {
79+
"@types/semver": "^7.7.0",
80+
"ioredis": "^5.6.1",
81+
"semver": "^7.7.1",
82+
"uuid": "^11.1.0"
7783
}
7884
}

src/classes/async-fifo-queue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LinkedList<T> {
2323
this.head = newNode
2424
}
2525
else {
26-
this.tail.next = newNode
26+
this.tail!.next = newNode
2727
}
2828

2929
this.tail = newNode
@@ -37,7 +37,7 @@ class LinkedList<T> {
3737
}
3838
else {
3939
const head = this.head
40-
this.head = this.head.next
40+
this.head = this.head!.next
4141
this.length -= 1
4242

4343
return head
@@ -91,7 +91,7 @@ export class AsyncFifoQueue<T> {
9191
.catch((err) => {
9292
// Ignore errors
9393
if (this.ignoreErrors) {
94-
this.queue.push(undefined)
94+
this.queue.push(undefined as unknown as T)
9595
}
9696
this.pending.delete(promise)
9797
this.rejectPromise(err)

src/classes/child-pool.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { SandboxedOptions } from '../interfaces'
22
import * as path from 'node:path'
3+
import process from 'node:process'
34
import { Child } from './child'
45

56
const CHILD_KILL_TIMEOUT = 30_000
@@ -31,11 +32,11 @@ export class ChildPool {
3132
let child = this.getFree(processFile).pop()
3233

3334
if (child) {
34-
this.retained[child.pid] = child
35+
this.retained[child.pid as number] = child
3536
return child
3637
}
3738

38-
child = new Child(this.opts.mainFile, processFile, {
39+
child = new Child(this.opts.mainFile!, processFile, {
3940
useWorkerThreads: this.opts.useWorkerThreads,
4041
workerForkOptions: this.opts.workerForkOptions,
4142
workerThreadsOptions: this.opts.workerThreadsOptions,
@@ -52,7 +53,7 @@ export class ChildPool {
5253
throw new Error('Child exited before it could be retained')
5354
}
5455

55-
this.retained[child.pid] = child
56+
this.retained[child.pid as number] = child
5657

5758
return child
5859
}
@@ -64,12 +65,12 @@ export class ChildPool {
6465
}
6566

6667
release(child: Child): void {
67-
delete this.retained[child.pid]
68+
delete this.retained[child.pid as number]
6869
this.getFree(child.processFile).push(child)
6970
}
7071

7172
remove(child: Child): void {
72-
delete this.retained[child.pid]
73+
delete this.retained[child.pid as number]
7374

7475
const free = this.getFree(child.processFile)
7576

src/classes/child-processor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Receiver, SandboxedJob } from '../interfaces'
22
import type { JobJsonSandbox, JobProgress } from '../types'
3+
import process from 'node:process'
34
import { ParentCommand } from '../enums'
45
import { errorToJSON } from '../utils'
56

src/classes/child.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ export class Child extends EventEmitter {
5050
super()
5151
}
5252

53-
get pid() {
53+
get pid(): number | undefined {
5454
if (this.childProcess) {
5555
return this.childProcess.pid
5656
}
57-
else if (this.worker) {
57+
58+
if (this.worker) {
5859
// Worker threads pids can become negative when they are terminated
5960
// so we need to use the absolute value to index the retained object
6061
return Math.abs(this.worker.threadId)
6162
}
62-
else {
63-
throw new Error('No child process or worker thread')
64-
}
63+
64+
throw new Error('No child process or worker thread')
6565
}
6666

6767
get exitCode() {

src/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type {
77
Span,
88
Tracer,
99
} from './interfaces'
10+
import { Buffer } from 'node:buffer'
11+
import process from 'node:process'
1012
import { Cluster } from 'ioredis'
1113
import { CONNECTION_CLOSED_ERROR_MSG } from 'ioredis/built/utils'
1214
import * as semver from 'semver'
@@ -182,8 +184,7 @@ export function getParentKey(opts: {
182184
}
183185
}
184186

185-
export const clientCommandMessageReg
186-
= /ERR unknown command ['`]\s*client\s*['`]/
187+
export const clientCommandMessageReg = /ERR unknown command ['`]\s*client\s*['`]/
187188

188189
export const DELAY_TIME_5 = 5000
189190

@@ -284,7 +285,7 @@ export function toString(value: any): string {
284285
}
285286
if (
286287
typeof value == 'symbol'
287-
|| Object.prototype.toString.call(value) == '[object Symbol]'
288+
|| Object.prototype.toString.call(value) === '[object Symbol]'
288289
) {
289290
return value.toString()
290291
}
@@ -373,7 +374,7 @@ export async function trace<T>(
373374
messageContext = span.setSpanOnContext(currentContext)
374375
}
375376

376-
if (callback.length == 2) {
377+
if (callback.length === 2) {
377378
dstPropagationMetadata = contextManager.getMetadata(messageContext)
378379
}
379380

0 commit comments

Comments
 (0)