Skip to main content

Applications

Reboot applications are defined using an instance of Application, and launched from the file configured as your --application in .rbtrc.

Application

Your entrypoint will construct an Application, and then run it:

async def main():
await Application(
servicers=[HelloServicer],
initialize=initialize,
).run()


if __name__ == '__main__':
asyncio.run(main())

initialize functions

The optional initialize argument to the Application constructor is a function which runs every time your application starts up.

Initializers can be used to create any initial state that your application needs. In particular, they are usually where any singleton states used by your application are created.

async def initialize(context: ExternalContext):
hello = Hello.lookup(EXAMPLE_STATE_MACHINE_ID)

# Implicitly construct state machine upon first write.
await hello.idempotently().Send(
context,
message="Hello, World!",
)

If you have declared an initialize function, then you can additionally pass an initialize_bearer_token (initializeBearerToken in TypeScript) which the initialize method should use to authenticate itself to your application.

Idempotency

Similar to a workflow method, all calls from an initialize function must be idempotent, because it will be re-run each time your application starts, and retried when it fails.

Thanks to idempotency, every call your application makes in initialize() will only execute one time; previously-run calls are skipped when initialize() re-runs later. It is important that initialize() does re-run every time your application starts: it allows you to add new calls to initialize() as your application evolves, with each of those calls also running exactly once.