Is there any random time trigger?

Search the keyword “random time” and “random schedule” in the forum, nothing found.

I would like to have a trigger which could be activated once per day at a random time in a given time interval, but the trigger I could find is fixed-time trigger. Is there any api function to assign the trigger value for the next execution? Or is it allowed to run some node code for trigger? The last choice might be “sleep()” in node code, which takes up the execution time limit.

@z19941225110 that’s a cool use case. I’d suggest checking out our task scheduler, which allows you to schedule a workflow execution at a specific time in the future. Once you’ve setup a task scheduler source, you can schedule new tasks a random number of seconds within the next day:

Math.floor(Math.random() * 86400)

Let me know if that helps.

Ok, but it is possible to make it with Cron Scheduler? It’s too complicated for me :confused:

@fupl-9bd671 No, unfortunately Cron has no built-in way to schedule items at a random time. But running these tasks using the Task Scheduler is less complicated than it might seem at first.

  1. First, create a Task Scheduler source.
  2. Create a new workflow, and select the option to Use one of your existing sources. Select the Task Scheduler source you created in step 1.
  3. Add whatever logic you’d like to run at this random time. For example, if you want to post a tweet, add that step to your workflow. This will run each time the workflow executes at the random time.
  4. Add the Pipedream Task Scheduler - Schedule Task step at the end of your workflow. In the Num Seconds param, enter something like this:
{{ Math.floor( / 1000) + Math.floor(Math.random() * 86400) }}

This will schedule the next task randomly sometime within the next 24 hours (86400 seconds). To narrow the interval and schedule tasks randomly within 6 hours, you can replace 86400 with 21600 (the number of seconds in 6 hours):

{{ Math.floor( / 1000) + Math.floor(Math.random() * 21600) }}

Enter the URL of your Task Scheduler from step 1 as the Task Scheduler URL, and enter any data in the Message param (this isn’t relevant for your use case):

If you runt the workflow once, it will start the random scheduler, and it should run until you pause the workflow.

Give it a try and let me know if you have specific questions we can help with!