Is there a way to create a workflow to pause or unpause another work flow?

I’ve got some jobs that only need to run for a little awhile after another job runs — I’m currently handling this by a schedule but this creates hundreds of wasted credits a day. I would love to be able to add a function that could turn on a task or turn off a task (example I have a job that looks for a success flag and then sends a slack announcement that the task is done). The main use case I have is, I have a job that kicks off a refresh of a PBI data set, and then I could add a function to turn on the REST API checker (another job that checks the refreshes API for a success flag), and then would turn it self off once it completes. This would be a HUGE credit saver for me! Is this something we could potentially add or does anyone know a work around for this?

What you need is $.flow.rerun().

but would flow.rerun work for an approximately 2-3 hour window (i apologize “little while” can be relative)? Would I need to up the retries and timeout delays to the point it wouldn’t make sense credit wise?

I do have some processes where this makes sense-- but I’ve got one big one-- where I’d need it to stay open for a couple hours (it’s a big PBI model and it can fail a few times keeping the refresh open for about 2-3 hours)

It’s certainly better than a schedule. And workflows can be suspended for days, so a few hours is nothing.

Credit wise, you can adjust how often the workflow is resumed (which will incur a new credit/execution each time). You can resume/poll every minute, every 5 minutes, every 30 minutes, or anything else. This allows you to adjust how much you want to spend vs how early you want to know when it is done.

You could even use the data store to dynamically determine the polling frequency:

  • If you are waiting for a lot of jobs to complete (i.e. entries in the data store), then suspend for only 5 minutes.
  • But if there are no jobs currently running (according to the data store), you could suspend for 30 minutes instead.
  • You could even adapt the schedule according to the time of day. For example, if you know that no jobs run in the afternoon, then you could suspend the workflow for a couple of hours.

This gives you programmatic control over the schedule, rather than being bound to a single hardcoded schedule (every X minutes, no matter what).

It’s this simple:

$.flow.rerun(
  delay, // The number of milliseconds until the step will be rerun
  context, // JSON-serializable data you need to pass between runs
  maxRetries // The total number of times the step will rerun. Defaults to 10
);

So you could go with something like this:

let delay = ???; // Implement your polling logic here.
$.flow.rerun(delay, {}, 999999999); // Never stop polling
1 Like

Right on— I can take a peak at these! So the rerun just pauses the workflow and then kicks off from the same spot on the delay polling time specified? Essentially I’m kicking off a refresh of data and polling the API to see when it completes. Ideally I coould poll until an success\completed event happens, then just let the job finish out?

1 Like

Exactly!

It doesn’t kick off from the same line in the code though. It reruns the entire code step, so it requires a bit of code to handle. The documentation shows what to do.

I think they also added some user friendly prebuilt actions for reruns that don’t require a ton of Node.js script… I’ll take a peak at that too

nope— I lied, i thought I saw rerun in the prebuilts-- I know pause is.

I wish they would make a “Repoll until condition is met” prebuilt— kinda like the “continue_based_on_condition” – but just add in a “repoll option” until the condition is met… @michael — do you know if this is something in the pipeline of requested adds?

Well, branching and looping is coming soon, so I guess you could do that with a loop.

Just keep looping/polling until the condition is met.

Assuming that looping supports while loops, and not only for loops.

1 Like