Skip to content

Commit

Permalink
Idempotence (GSI-626) (#12)
Browse files Browse the repository at this point in the history
* Update template files and lock files

* Add mongodb provider from hexkit

* Add mongodb config

* Add model for storing hash sums of notification events

* Add DAO for notification records

* Update Notifier to use new DAO

* Update the joint fixture

* Update pyproject config for ruff linting

* Update existing tests to use notifier in joint fixture

Also removes some outdated calls to stop the event loop

* Make _controller loop stop call conditional

* Update model field directly before update

* Add tests for new functionality

* Update readme for the config

* Make _ensure_not_sent func more intuitive

* Don't check email str existence

* Remove unnecessary imports in test

* Type cast the Notifier instead of using type ignores

* Rename _check_if_sent to _has_been_sent

---------

Co-authored-by: TheByronHimes <[email protected]>
  • Loading branch information
TheByronHimes and TheByronHimes authored Mar 4, 2024
1 parent 03a1b85 commit 33f66ed
Show file tree
Hide file tree
Showing 23 changed files with 1,151 additions and 658 deletions.
2 changes: 2 additions & 0 deletions .devcontainer/.dev_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ login_user: "[email protected]"
login_password: test
from_address: "[email protected]"
use_starttls: false
db_connection_str: "mongodb://mongodb:27017"
db_name: "dev_db"
2 changes: 1 addition & 1 deletion .github/workflows/ci_workflow_dispatch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
fetch-tag:
runs-on: ubuntu-latest
if: ( github.event.action == 'workflow_dispatch' || github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'build') ) || ( github.event.action == 'labeled' && github.event.label.name == 'build' )
if: github.event_name == 'workflow_dispatch' || ( github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'build') ) || ( github.event.action == 'labeled' && github.event.label.name == 'build' )
steps:
- id: fetch-tag
uses: ghga-de/gh-action-fetch-tag@v1
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ repos:
- id: no-commit-to-branch
args: [--branch, dev, --branch, int, --branch, main]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
6 changes: 3 additions & 3 deletions .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name = "ns"
version = "1.1.0"
description = "The Notification Service (NS) handles notification kafka events."
dependencies = [
"typer>=0.7.0",
"typer>=0.9.0",
"ghga-event-schemas>=3.0.0, <4",
"ghga-service-commons>=1.2.0",
"hexkit[akafka]>=1.0.0",
"ghga-service-commons>=2.0.0",
"hexkit[akafka,mongodb]>=2.0.0",
]

[project.urls]
Expand Down
24 changes: 13 additions & 11 deletions .pyproject_generation/pyproject_template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ exclude = [
"build",
"dist",
]
line-length = 88
src = ["src", "tests", "examples", "scripts"]
target-version = "py39"

[tool.ruff.lint]
fixable = [
"UP", # e.g. List -> list
"I", # sort imports
"D", # pydocstyle
]
ignore = [
"E", # pycodestyle errors
"W", # pycodestyle warnings - pycodestyle covered by black
Expand All @@ -49,7 +59,6 @@ ignore = [
"D206", # indent-with-spaces (ignored for formatter)
"D300", # triple-single-quotes (ignored for formatter)
]
line-length = 88
select = [
"C90", # McCabe Complexity
"F", # pyflakes codes
Expand All @@ -63,25 +72,18 @@ select = [
"SIM", # flake8-simplify
"D", # pydocstyle
]
fixable = [
"UP", # e.g. List -> list
"I", # sort imports
"D", # pydocstyle
]
src = ["src", "tests", "examples", "scripts"]
target-version = "py39"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"scripts/*" = ["PL", "S", "SIM", "D"]
"tests/*" = ["S", "SIM", "PLR", "B011"]
".devcontainer/*" = ["S", "SIM", "D"]
"examples/*" = ["S", "D"]
"__init__.py" = ["D"]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "pep257"

[tool.mypy]
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ ns --help
### Parameters

The service requires the following configuration parameters:
- **`db_connection_str`** *(string, format: password)*: MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/.


Examples:

```json
"mongodb://localhost:27017"
```


- **`db_name`** *(string)*: Name of the database located on the MongoDB server.


Examples:

```json
"my-database"
```


- **`log_level`** *(string)*: The minimum log level to capture. Must be one of: `["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE"]`. Default: `"INFO"`.

- **`service_name`** *(string)*: Default: `"ns"`.
Expand Down
20 changes: 20 additions & 0 deletions config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
"additionalProperties": false,
"description": "Modifies the orginal Settings class provided by the user",
"properties": {
"db_connection_str": {
"description": "MongoDB connection string. Might include credentials. For more information see: https://naiveskill.com/mongodb-connection-string/",
"examples": [
"mongodb://localhost:27017"
],
"format": "password",
"title": "Db Connection Str",
"type": "string",
"writeOnly": true
},
"db_name": {
"description": "Name of the database located on the MongoDB server.",
"examples": [
"my-database"
],
"title": "Db Name",
"type": "string"
},
"log_level": {
"default": "INFO",
"description": "The minimum log level to capture.",
Expand Down Expand Up @@ -165,6 +183,8 @@
}
},
"required": [
"db_connection_str",
"db_name",
"service_instance_id",
"plaintext_email_template",
"html_email_template",
Expand Down
2 changes: 2 additions & 0 deletions example_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
db_connection_str: '**********'
db_name: dev_db
from_address: [email protected]
generate_correlation_id: true
html_email_template: '<!DOCTYPE html><html><head></head><body style="color: #00393f;padding:
Expand Down
4 changes: 2 additions & 2 deletions lock/requirements-dev-template.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ ruff>=0.0.290
click>=8.1.0
typer>=0.7.0

httpx>=0.23.3
pytest-httpx>=0.21.3
httpx>=0.26.0
pytest-httpx>=0.29.0

urllib3>=1.26.15
requests>=2.28.2
Expand Down
Loading

0 comments on commit 33f66ed

Please sign in to comment.