How can I set up a delayed re-run for a workflow using Pipedream API?

This topic was automatically generated from Slack. You can find the original thread here.

Hey guys, I’m trying to set up re-runs for a workflow that I’m running. I need the rerun to be triggered after a delay of about 15 mins. I’ve set up an error listener workflow to catch the ID and set up a delay in the next step. I generated some code (which I’ll attach in the thread) to try to use the pipedream api to trigger the re run. However I don’t think it is actually functioning and I’m not sure why. Is this the best way to do this?

import { axios } from "@pipedream/platform";

export default defineComponent({
  props: {
    workflowId: {
      type: "string",
      label: "Workflow ID",
      description: "The ID of the workflow to rerun",
      default: "2NxdaZEW9E5YMyHJTEtuD3N4BBy",
    },
  },
  async run({ $ }) {
    const rerunUrl = `https://api.pipedream.com/v1/workflows/${this.workflowId}/rerun`;

    try {
      const response = await axios($, {
        method: "POST",
        url: rerunUrl,
        headers: {
          Authorization: `Bearer ${process.env.PIPEDREAM_API_KEY}`,
        },
      });

      return response;
    } catch (error) {
      console.error("Error rerunning the workflow:", error);
      throw error;
    }
  },
});

Hello , I think to rerun a workflow, the approriate way should be adding the HTTP trigger to your workflow, then call the HTTP Endpoint in your second workflow. For example:

The first workflow has the HTTP trigger with the endpoint https://eo2s1f43oqhpya7.m.pipedream.net (1st image below)

So on the second workflow, you can use axios call to that endpoint

Hey Leo, I’m not sure that will work here. Because I’m trying to rerun specific failed events from a workflow which already has a trigger (that I cannot replace).

Thanks for the information,may I ask where did you find the reference for /rerun API?

Yeah that is the problem. I generated the code and then found out that I couldn’t find any reference.

Yeah I think that API is not existing. I tried to find it in Pipedream REST API page but it did not exists

I’m thinking of a workaround for you. May I ask in your failed event, is there data included? If the data is included, you can add that data as the body in your HTTP request to your first workflow, so that your first workflow will process that data again

Ah yeah that is an idea. So you’d suggest to duplicate the workflow and then trigger it with webhook in that duplicate?

You don’t need to duplicate your workflow, you can add multiple triggers into the same workflow (In your case, it would be your first workflow). Just follow the steps below

As long as your triggers return the same data structure, then your action should work the same

Ah right, I think that could work. I’ll give it a shot! thanks :slightly_smiling_face:

I had a play around with it. Difficulty is that my original trigger has all of its data under steps.trigger.event while for the webhook trigger I can only get it under steps.trigger.body.event. I’m not sure how I can clean that up for use

, I apologize for the late response. In this case you can add a simple code step to get the data out of the event, and modify your action to use the data from that code step instead. For example:

// To use previous step data, pass the `steps` object to the run() function
export default defineComponent({
  async run({ steps, $ }) {
    // Return data to use it in future steps
    return steps.trigger.event || steps.trigger.body.event
  },
})

Please see the image below. Now in your workflow, instead using steps.trigger.event or steps.trigger.body.event, you should use steps.get_event.$return_value

I wonder if $.flow.delay() or $.flow.rerun() might be what you’re looking for also, Pause, resume, and rerun a workflow

Thanks I’ll give that a shot.

I guess that could work. Tricky thing might be that in my current setup the error in one step can be caused by an error in the previous step (data not yet available). So I need to delay it and then retry the previous step.

For sure possible to rewrite the two step process into one codestep and then applying the $.flow.rerun() to the first one if it errors or doesn’t return the expected data. I’ll keep that as food for thought :slightly_smiling_face:

Also FYI on the Advanced Plan you get Auto-Retry as a built-in feature Settings

I don’t see a advanced plan in the pricing overview? I just see professional and the org plans

Hello , I think the plan will coming soon! Please stay tunes for updates!