Skip to content

Commit fa1b7c4

Browse files
committed
feat: short sleeps
1 parent 8cc18ce commit fa1b7c4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

libs/definitions/src/integration-definitions/sleep/actions/sleep-for.action.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { wait } from '@app/common/utils/async.utils'
12
import { RunResponse } from '@app/definitions/definition'
23
import { OperationOffChain } from '@app/definitions/opertion-offchain'
34
import { BadRequestException } from '@nestjs/common'
@@ -44,10 +45,23 @@ export class SleepForAction extends OperationOffChain {
4445
if (sleepUntil === null) {
4546
throw new BadRequestException('Invalid sleep duration')
4647
}
48+
const sleepSeconds = Math.round((sleepUntil.getTime() - Date.now()) / 1000)
49+
50+
// short sleeps don't need to be scheduled
51+
if (sleepSeconds <= 60) {
52+
await wait(sleepSeconds * 1000)
53+
return {
54+
outputs: {
55+
sleepUntil: sleepUntil.toISOString(),
56+
sleepSeconds,
57+
},
58+
}
59+
}
60+
4761
return {
4862
outputs: {
4963
sleepUntil: sleepUntil.toISOString(),
50-
sleepSeconds: Math.round((sleepUntil.getTime() - Date.now()) / 1000),
64+
sleepSeconds,
5165
},
5266
sleepUntil,
5367
}

0 commit comments

Comments
 (0)