Skip to main content

Long running actions

By default, an action is terminated when the person running the action leaves the page.

While we think this is a solid default, it isn't a desirable behavior when creating long running actions like batch migration tools.

To solve for this, Interval allows you to mark an action as backgroundable, meaning it continues running even when you leave the page.

There are two ways to make an action backgroundable.

In code, you can specify backgroundable = true when defining your action:

import Interval from "@interval/sdk";

const interval = new Interval({
apiKey: "<YOUR API KEY>", // get an API key at https://interval.com/dashboard/develop/keys
actions: {
import_data: {
handler: async () => {
// action logic here
},
backgroundable: true,
},
},
});

interval.listen();

Alternatively, you can override the backgroundable behavior from your code through the configuration page for an action:

When an action is running the background, the person running it will automatically receive a notification when it completes or requires input.

Backgroundability makes Interval a powerful tool for writing resilient code. For example, instead of erroring on an unexpected condition in a long running job, you can easily prompt for user intervention.

Was this section useful?