Trigger RANDOM (cron random)

How set random trigger? (one per day)

I see in old post:
" 1. 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(Date.now() / 1000) + Math.floor(Math.random() * 86400) }}

"
but

I don’t see “Pipedream Task Scheduler” only trigger Schedule:

and I can’t set cron 0 * * * * RANDOM in this trigger

Hi @fbox3tv33,

You can achieve a random daily trigger using the Custom Interval trigger in the Schedule app. First, create a new workflow and follow these steps:

  1. Search for the Schedule app from the trigger menu.
  2. Select the Custom Interval trigger.
  3. Connect your Schedule account.
  4. In the “Cron Expression” field, enter a cron expression like 0 * * * *, which will run the workflow every hour.
  5. Save the trigger.

Now, add a Node.js code step to your workflow with the following code:

export default defineComponent({
  async run({ $ }) {
    const randomMinutes = Math.floor(Math.random() * 60);
    if (randomMinutes === 0) {
      // Your desired action or code to run once per day at a random time
      console.log("Random daily trigger executed");
    } else {
      console.log("Not executing at this hour");
    }
  },
});

This code will generate a random number between 0 and 59 (inclusive) for each hour the workflow runs. If the random number is 0, the code inside the if block will execute, effectively running your desired action once per day at a random time.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

How Connect your Schedule account?