Hello, I have a workflow that runs based on “Custom Interval” triggers.
I want to stop execution of the workflow if it is a weekend.
Current script returns TIMEOUT error.
How can I do that?
Here is the workflow…
Thanks.
Hi @slishnevsky,
To stop the execution of your workflow on weekends, you can use JavaScript’s Date
object to check the day of the week and then conditionally exit the workflow if it’s a weekend. The Date
object’s getDay()
method returns the day of the week as an integer, where 0 represents Sunday and 6 represents Saturday. Here’s how you can modify your workflow to include this logic:
async run({ steps, $ }) {
// Get the current day of the week (0-6)
const dayOfWeek = new Date().getDay();
// Check if the current day is Saturday (6) or Sunday (0)
if (dayOfWeek === 0 || dayOfWeek === 6) {
// Exit the workflow without performing any further actions
$.flow.exit("Skipping execution on the weekend");
}
// Your existing workflow logic here
}
This script should be placed at the beginning of your workflow. It checks the current day and uses $.flow.exit
to stop the workflow execution if it’s a weekend, avoiding the timeout error you encountered. For weekdays, the workflow will continue to execute as normal.
Remember, the timeout error you’re experiencing is likely unrelated to the check for weekends and might be due to long-running operations within your workflow. If you continue to experience timeout errors on weekdays, consider reviewing your workflow for steps that might be taking longer than expected and adjust accordingly.
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.