Skip to content

Commit

Permalink
Export middleware via experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Nov 4, 2023
1 parent 619c11e commit 3c1ac99
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
11 changes: 0 additions & 11 deletions inngest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
TriggerCron,
TriggerEvent,
)

# TODO: Uncomment when middleware is ready for external use.
# from ._internal.middleware_lib import (
# Middleware,
# MiddlewareSync,
# )
# from ._internal.execution import TransformableCallInput
from ._internal.step_lib import Step, StepSync
from ._internal.types import Logger, Serializable

Expand All @@ -29,10 +22,6 @@
"Function",
"Inngest",
"Logger",
# TODO: Uncomment when middleware is ready for external use.
# "Middleware",
# "MiddlewareSync",
# "TransformableCallInput",
"NonRetriableError",
"RateLimit",
"Serializable",
Expand Down
8 changes: 8 additions & 0 deletions inngest/experimental.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ._internal.execution import TransformableCallInput
from ._internal.middleware_lib import Middleware, MiddlewareSync

__all__ = [
"Middleware",
"MiddlewareSync",
"TransformableCallInput",
]
22 changes: 10 additions & 12 deletions tests/cases/client_middleware.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import typing

import inngest
import inngest.experimental
import tests.helper

# TODO: Remove when middleware is ready for external use.
from inngest._internal import execution, middleware_lib, types

from . import base

_TEST_NAME = "client_middleware"
Expand All @@ -25,11 +23,11 @@ def create(
state = _State()

middleware: typing.Type[
middleware_lib.Middleware | middleware_lib.MiddlewareSync
inngest.experimental.Middleware | inngest.experimental.MiddlewareSync
]
if is_sync:

class _MiddlewareSync(middleware_lib.MiddlewareSync):
class _MiddlewareSync(inngest.experimental.MiddlewareSync):
def after_execution(self) -> None:
state.hook_list.append("after_execution")

Expand All @@ -41,8 +39,8 @@ def before_execution(self) -> None:

def transform_input(
self,
call_input: execution.TransformableCallInput,
) -> execution.TransformableCallInput:
call_input: inngest.experimental.TransformableCallInput,
) -> inngest.experimental.TransformableCallInput:
state.hook_list.append("transform_input")
return call_input

Expand All @@ -57,7 +55,7 @@ def transform_output(

else:

class _MiddlewareAsync(middleware_lib.Middleware):
class _MiddlewareAsync(inngest.experimental.Middleware):
async def after_execution(self) -> None:
state.hook_list.append("after_execution")

Expand All @@ -69,8 +67,8 @@ async def before_execution(self) -> None:

async def transform_input(
self,
call_input: execution.TransformableCallInput,
) -> execution.TransformableCallInput:
call_input: inngest.experimental.TransformableCallInput,
) -> inngest.experimental.TransformableCallInput:
state.hook_list.append("transform_input")
return call_input

Expand All @@ -90,7 +88,7 @@ async def transform_output(
)
def fn_sync(
*,
logger: types.Logger,
logger: inngest.Logger,
step: inngest.StepSync,
run_id: str,
**_kwargs: object,
Expand Down Expand Up @@ -118,7 +116,7 @@ def _second_step() -> None:
)
async def fn_async(
*,
logger: types.Logger,
logger: inngest.Logger,
step: inngest.Step,
run_id: str,
**_kwargs: object,
Expand Down
20 changes: 9 additions & 11 deletions tests/cases/function_middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import inngest
import inngest.experimental
import tests.helper

# TODO: Remove when middleware is ready for external use.
from inngest._internal import execution, middleware_lib, types

from . import base

_TEST_NAME = "function_middleware"
Expand All @@ -22,7 +20,7 @@ def create(
event_name = base.create_event_name(framework, test_name, is_sync)
state = _State()

class _MiddlewareSync(middleware_lib.MiddlewareSync):
class _MiddlewareSync(inngest.experimental.MiddlewareSync):
def after_execution(self) -> None:
state.hook_list.append("after_execution")

Expand All @@ -36,8 +34,8 @@ def before_execution(self) -> None:

def transform_input(
self,
call_input: execution.TransformableCallInput,
) -> execution.TransformableCallInput:
call_input: inngest.experimental.TransformableCallInput,
) -> inngest.experimental.TransformableCallInput:
state.hook_list.append("transform_input")
return call_input

Expand All @@ -48,7 +46,7 @@ def transform_output(
state.hook_list.append("transform_output")
return output

class _MiddlewareAsync(middleware_lib.Middleware):
class _MiddlewareAsync(inngest.experimental.Middleware):
async def after_execution(self) -> None:
state.hook_list.append("after_execution")

Expand All @@ -62,8 +60,8 @@ async def before_execution(self) -> None:

async def transform_input(
self,
call_input: execution.TransformableCallInput,
) -> execution.TransformableCallInput:
call_input: inngest.experimental.TransformableCallInput,
) -> inngest.experimental.TransformableCallInput:
state.hook_list.append("transform_input")
return call_input

Expand All @@ -82,7 +80,7 @@ async def transform_output(
)
def fn_sync(
*,
logger: types.Logger,
logger: inngest.Logger,
step: inngest.StepSync,
run_id: str,
**_kwargs: object,
Expand Down Expand Up @@ -111,7 +109,7 @@ def _second_step() -> None:
)
async def fn_async(
*,
logger: types.Logger,
logger: inngest.Logger,
step: inngest.Step,
run_id: str,
**_kwargs: object,
Expand Down

0 comments on commit 3c1ac99

Please sign in to comment.