File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
libs/definitions/src/integration-definitions/sleep/actions Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1+ import { wait } from '@app/common/utils/async.utils'
12import { RunResponse } from '@app/definitions/definition'
23import { OperationOffChain } from '@app/definitions/opertion-offchain'
34import { 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 }
You can’t perform that action at this time.
0 commit comments