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.
- TypeScript
- JavaScript
- Python
In code, you can specify backgroundable: true
when defining your action:
import { Action } from "@interval/sdk";
export default new Action({
backgroundable: true,
handler: async () => {
// action logic here
},
});
In code, you can specify backgroundable: true
when defining your action:
const { Action } = require("@interval/sdk");
module.exports = new Action({
backgroundable: true,
handler: async () => {
// action logic here
},
});
In code, you can specify backgroundable=True
when defining your action:
import os
from interval_sdk import Interval, IO, ctx_var
interval = Interval(
os.environ["INTERVAL_API_KEY"],
)
@interval.action(backgroundable=true)
async def import_data(io: IO):
# action logic here
pass
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.