mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
New "startup" plugin hook, closes #834
This commit is contained in:
parent
b906030235
commit
09a3479a54
8 changed files with 61 additions and 0 deletions
|
|
@ -302,6 +302,13 @@ class Datasette:
|
|||
self._permission_checks = collections.deque(maxlen=200)
|
||||
self._root_token = secrets.token_hex(32)
|
||||
|
||||
async def invoke_startup(self):
|
||||
for hook in pm.hook.startup(datasette=self):
|
||||
if callable(hook):
|
||||
hook = hook()
|
||||
if asyncio.iscoroutine(hook):
|
||||
hook = await hook
|
||||
|
||||
def sign(self, value, namespace="default"):
|
||||
return URLSafeSerializer(self._secret, namespace).dumps(value)
|
||||
|
||||
|
|
|
|||
|
|
@ -397,6 +397,9 @@ def serve(
|
|||
# Private utility mechanism for writing unit tests
|
||||
return ds
|
||||
|
||||
# Run the "startup" plugin hooks
|
||||
asyncio.get_event_loop().run_until_complete(ds.invoke_startup())
|
||||
|
||||
# Run async sanity checks - but only if we're not under pytest
|
||||
asyncio.get_event_loop().run_until_complete(check_databases(ds))
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ hookspec = HookspecMarker("datasette")
|
|||
hookimpl = HookimplMarker("datasette")
|
||||
|
||||
|
||||
@hookspec
|
||||
def startup(datasette):
|
||||
"Fires directly after Datasette first starts running"
|
||||
|
||||
|
||||
@hookspec
|
||||
def asgi_wrapper(datasette):
|
||||
"Returns an ASGI middleware callable to wrap our ASGI application with"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue