Skip to content

automaNextBlock() does not continue to next block after setTimeout() #2100

@abacusit

Description

@abacusit

I have the following javascript code to pause the workflow until certain time. The code seems to work as expected, as the "alert()" function pops up at the desired time. But after the alert, the workflow is still in waiting. In the log, the work flow keeps running. I have to manually terminate it. The block after the javascript never runs.

async function delayUntilTime(targetHour, targetMinute) {

  const now = new Date();
  const targetTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), targetHour, targetMinute, 0, 0);

  // If the target time has already passed today, set it for tomorrow
  if (now > targetTime) {
    targetTime.setDate(targetTime.getDate() + 1);
  }

  const delayDuration = targetTime.getTime() - now.getTime();
  
  console.log(`Waiting for ${delayDuration / 1000} seconds until ${targetTime.toLocaleTimeString()}`);
  console.log(delayDuration);
  
  await new Promise(resolve => setTimeout(resolve, delayDuration));
  alert('timeout!');
  automaNextBlock();

}

// Call the function with your desired time (e.g., 8 AM)
delayUntilTime(0, 8);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions