Skip to content

Commit 2de1a4f

Browse files
authored
Generate unique job id. (#931)
1 parent 2b01f32 commit 2de1a4f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/components/core/compute/startCompute.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,13 @@ export class PaidComputeStartHandler extends CommandHandler {
352352
agreementId: '',
353353
resources
354354
}
355-
const jobId = createHash('sha256').update(JSON.stringify(s)).digest('hex')
355+
// job ID unicity
356+
const timestamp =
357+
BigInt(Date.now()) * 1_000_000n + (process.hrtime.bigint() % 1_000_000n)
358+
const random = Math.random()
359+
const jobId = createHash('sha256')
360+
.update(JSON.stringify(s) + timestamp.toString() + random.toString())
361+
.digest('hex')
356362
// let's calculate payment needed based on resources request and maxJobDuration
357363
const cost = engine.calculateResourcesCost(
358364
task.payment.resources,

0 commit comments

Comments
 (0)