This topic was automatically generated from Slack. You can find the original thread here.
Is there a way to retry the same NodeJS step up to 5 times with 5 min delay between each retry? I cannot use a JS timeout as it will reach the PD timeout. I also cannot use the $.flow.delay() as it will only delay the automation until the NEXT step, whereas I need to delay the execution before it runs the same step. Is this possible?
Yes, you can achieve this by using the $.flow.rerun function in Pipedream. This function allows you to rerun a specific step multiple times with a delay between each retry. Here’s how you can set it up to retry a Node.js step up to 5 times with a 5-minute delay between each retry: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ $ }) { const MAX_RETRIES = 5; const DELAY = 5 ** 60 ** 1000; // 5 minutes in milliseconds const { run } = $.context; // Check the number of times the step has been run if (run.runs <= MAX_RETRIES) { try { // Your code logic here // For example, making an API request const response = await axios($, { method: “GET”, url: “https://example.com/api”, }); // If successful, return the response return response; } catch (error) { // If an error occurs, schedule a retry $.flow.rerun(DELAY, null, MAX_RETRIES); } } else { throw new Error(“Max retries exceeded”); } }, });