Interval
The Interval
class is the entrypoint for defining
actions and pages.
Usage
- TypeScript
- JavaScript
- Python Experimental
import path from "path";
import { Interval } from "@interval/sdk";
const interval = new Interval({
apiKey: "<YOUR API KEY>" // get an API key at https://interval.com/dashboard/develop/keys
routesDirectory: path.resolve(__dirname, "routes"),
});
interval.listen();
const path = require("path");
const { Interval } = require("@interval/sdk");
const interval = new Interval({
apiKey: "<YOUR API KEY>" // get an API key at https://interval.com/dashboard/develop/keys
routesDirectory: path.resolve(__dirname, "routes"),
});
interval.listen();
import os
from interval_sdk import Interval
interval = Interval(
api_key=os.environ["INTERVAL_API_KEY"],
)
interval.listen()
Props
- TypeScript
- JavaScript
- Python Experimental
apiKey
Required
string
routesDirectory
Optional
string
routes
Optional
Record<string, Action | Page>
logLevel
Optional
"quiet" | "info" | "debug"
retryIntervalMs
Optional
number
pingIntervalMs
Optional
number
pingTimeoutMs
Optional
number
closeUnresponsiveTimeoutMs
Optional
number
reinitializeBatchTimeoutMs
Optional
number
apiKey
Required
string
routesDirectory
Optional
string
routes
Optional
Record<string, Action | Page>
logLevel
Optional
"quiet" | "info" | "debug"
retryIntervalMs
Optional
number
pingIntervalMs
Optional
number
pingTimeoutMs
Optional
number
closeUnresponsiveTimeoutMs
Optional
number
reinitializeBatchTimeoutMs
Optional
number
api_key
Required
str
log_level
Optional
"quiet" | "info" | "debug"
retry_interval
Optional
float
ping_interval
Optional
float
ping_timeout
Optional
float
reinitialize_batch_timeout
Optional
float
Methods
- TypeScript
- JavaScript
- Python Experimental
listen()
async safelyClose()
immediatelyClose()
listen()
async safelyClose()
immediatelyClose()
listen()
async safely_close()
async immediately_close()
Examples
Safely shutting down a live deployment (rolling deploys)
- TypeScript
- JavaScript
- Python Experimental
Leverage the safelyClose
method to ensure there are no service
interruptions, lost progress, or malformed data when shutting down a previous
version of a live deployment.
import path from "path";
import { Interval } from "@interval/sdk";
const interval = new Interval({
apiKey: "<YOUR API KEY>" // get an API key at https://interval.com/dashboard/develop/keys
routesDirectory: path.resolve(__dirname, "routes"),
});
interval.listen();
process.on('SIGINT', () => {
interval
.safelyClose()
.then(() => {
console.log("Safely shut down successfully.");
process.exit(0);
})
.catch(err => {
console.error(
"Failed shutting down safely, forcibly closing connection."
)
interval.immediatelyClose();
process.exit(0);
});
});
Leverage the safelyClose
method to ensure there are no service
interruptions when shutting down a previous version of a live
deployment.
const path = require("path");
const { Interval } = require("@interval/sdk");
const interval = new Interval({
apiKey: "<YOUR API KEY>" // get an API key at https://interval.com/dashboard/develop/keys
routesDirectory: path.resolve(__dirname, "routes"),
});
interval.listen();
process.on('SIGINT', () => {
interval
.safelyClose()
.then(() => {
console.log("Safely shut down successfully.");
process.exit(0);
})
.catch(err => {
console.error(
"Failed shutting down safely, forcibly closing connection."
)
interval.immediatelyClose();
process.exit(0);
});
});
Leverage the safely_close
method to ensure there are no service
interruptions when shutting down a previous version of a live
deployment.
import asyncio, os
from interval_sdk import Interval
interval = Interval(
api_key=os.environ["INTERVAL_API_KEY"],
)
loop = asyncio.get_event_loop()
task = loop.create_task(interval.listen_async())
close_task: asyncio.Task[None] | None = None
async def handle_close_inner():
try:
await interval.safely_close()
print("Safely shut down successfully.")
except Exception as err:
print("Failed shutting down safely, forcibly closing connection.", file=sys.stderr)
await interval.immediately_close()
def stop_loop(fut: asyncio.Future[None]):
fut.result()
loop.stop()
def handle_close():
global close_task
if close_task is not None:
return
close_task = loop.create_task(handle_close_inner())
close_task.add_done_callback(stop_loop)
loop.add_signal_handler(signal.SIGINT, handle_close)
loop.run_forever()