Skip to content

Commit

Permalink
[feature/PI-49-logging_with_step_chain]
Browse files Browse the repository at this point in the history
  • Loading branch information
jaklinger committed Oct 12, 2023
1 parent 6db3908 commit 4676f02
Show file tree
Hide file tree
Showing 42 changed files with 1,083 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ repos:
entry: json\.loads
language: pygrep
types: [python]
exclude: src/layers/event/json/__init__.py

- repo: local
hooks:
Expand All @@ -86,6 +87,7 @@ repos:
entry: json\.load
language: pygrep
types: [python]
exclude: src/layers/event/json/__init__.py

- repo: local
hooks:
Expand Down
193 changes: 192 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ packages = [
[tool.poetry.dependencies]
python = "3.11.4"
pydantic = "^2.4.2"
nhs-context-logging = "^0.2.7"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.4.0"
Expand All @@ -25,6 +26,8 @@ behave = "^1.2.6"
pytest = "^7.4.2"
pytest-custom-exit-code = "^0.3.0"
sh = "^2.0.6"
hypothesis = "^6.87.3"
aws-lambda-powertools = { extras = ["aws-sdk"], version = "^2.25.1" }

[build-system]
requires = ["poetry-core"]
Expand Down
37 changes: 37 additions & 0 deletions src/api/createProduct/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from event.environment import BaseEnvironment
from event.logging.logger import setup_logger
from event.logging.step_decorators import logging_step_decorators
from event.response.steps import response_steps
from event.step_chain import StepChain
from event.versioning.steps import get_steps_for_requested_version, versioning_steps


class Environment(BaseEnvironment):
SOMETHING: str


cache = {**Environment.model_construct().model_dump()}
step_decorators = [*logging_step_decorators]
pre_steps = [*versioning_steps]
post_steps = [*response_steps]


def handler(event: dict, context=None):
setup_logger(service_name=__file__)

pre_step_chain = StepChain(
step_chain=versioning_steps, step_decorators=step_decorators
)
pre_step_chain.run(init={"event": event, "__file__": __file__})

if isinstance(pre_step_chain.result, Exception):
result = pre_step_chain.result
else:
steps = pre_step_chain.data[get_steps_for_requested_version]
step_chain = StepChain(step_chain=steps, step_decorators=step_decorators)
step_chain.run(cache=cache, init=event)
result = step_chain.result

post_step_chain = StepChain(step_chain=post_steps, step_decorators=step_decorators)
post_step_chain.run(init=result)
return post_step_chain.result
9 changes: 9 additions & 0 deletions src/api/createProduct/src/v1/steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def a(data, cache):
return {"blah", "hi"}


def b(data, cache):
return {"a's result": data[a]}


steps = [a, b]
14 changes: 14 additions & 0 deletions src/api/createProduct/tests/test_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

from api.createProduct.index import handler


@pytest.mark.parametrize(
"version",
[
"1",
],
)
def test_index(version):
result = handler(event={"headers": {"version": version}})
assert result == "OK"
19 changes: 0 additions & 19 deletions src/api/createProduct/tests/test_placeholder_createProduct.py

This file was deleted.

Loading

0 comments on commit 4676f02

Please sign in to comment.