Async entrypoint for a Dagger module.
(mod: Module | None = None, register: bool = False)
| 31 | |
| 32 | |
| 33 | async def main(mod: Module | None = None, register: bool = False) -> int | None: |
| 34 | """Async entrypoint for a Dagger module.""" |
| 35 | # Establishing connection early on to allow returning dag.error(). |
| 36 | # Note: if there's a connection error dag.error() won't be sent but |
| 37 | # should be logged and the traceback shown on the function's stderr output. |
| 38 | async with await dagger.connect(): |
| 39 | try: |
| 40 | if mod is None: |
| 41 | mod = load_module() |
| 42 | if register: |
| 43 | return await mod.register() |
| 44 | return await mod.serve() |
| 45 | except (ModuleError, dagger.QueryError) as e: |
| 46 | await record_exception(e) |
| 47 | return 2 |
| 48 | except Exception as e: |
| 49 | logger.exception("Unhandled exception") |
| 50 | await record_exception(e) |
| 51 | return 1 |
| 52 | |
| 53 | |
| 54 | def load_module() -> Module: |
nothing calls this directly
no test coverage detected