Skip to content

Commit 21563bb

Browse files
author
Feraidoon Hamidi
committed
fix: [#56025] Handle to dates for extensions
1 parent 8218e56 commit 21563bb

23 files changed

+867
-964
lines changed

.pre-commit-config.yaml

+16-35
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
# SPDX-FileCopyrightText: 2023 Magenta ApS <https://magenta.dk>
1+
# SPDX-FileCopyrightText: 2022 Magenta ApS <https://magenta.dk>
22
# SPDX-License-Identifier: MPL-2.0
3-
43
default_language_version:
54
python: python3.11
65

76
repos:
87
- repo: https://github.com/asottile/pyupgrade
9-
rev: v3.4.0
8+
rev: v3.8.0
109
hooks:
1110
- id: pyupgrade
1211
args: [ "--py311-plus" ]
1312
exclude: |
1413
(?x)(
1514
^autogenerated_graphql_client/|
16-
^queries.graphql|
17-
^schema.graphql
1815
)
1916
17+
18+
2019
- repo: https://github.com/psf/black
21-
rev: 23.3.0
20+
rev: 23.7.0
2221
hooks:
2322
- id: black
2423
exclude: |
2524
(?x)(
2625
^autogenerated_graphql_client/|
27-
^queries.graphql|
28-
^schema.graphql
2926
)
3027
28+
29+
3130
- repo: https://github.com/asottile/reorder_python_imports
3231
rev: v3.10.0
3332
hooks:
3433
- id: reorder-python-imports
3534
exclude: |
3635
(?x)(
3736
^autogenerated_graphql_client/|
38-
^queries.graphql|
39-
^schema.graphql
4037
)
4138
39+
40+
4241
- repo: https://github.com/pycqa/flake8
4342
rev: 6.0.0
4443
hooks:
@@ -47,27 +46,24 @@ repos:
4746
exclude: |
4847
(?x)(
4948
^autogenerated_graphql_client/|
50-
^queries.graphql|
51-
^schema.graphql
5249
)
5350
5451
52+
53+
5554
- repo: https://github.com/pre-commit/mirrors-mypy
56-
rev: v1.4.0
55+
rev: v1.4.1
5756
hooks:
5857
- id: mypy
59-
args: [ "--ignore-missing-imports", "--config-file=pyproject.toml" ]
58+
args: [ "--ignore-missing-imports", "--config-file=pyproject.toml", "--no-strict-optional" ]
6059
additional_dependencies:
61-
- aiohttp
6260
- fastapi
61+
- gql
6362
- httpx
6463
- pydantic==1.10.11
65-
- starlette_context
66-
- strawberry-graphql
6764
- pytest
6865
- structlog
69-
- gql
70-
exclude: ^autogenerated_graphql_client/
66+
7167

7268
- repo: https://github.com/pre-commit/mirrors-prettier
7369
rev: v3.0.0-alpha.6
@@ -90,36 +86,21 @@ repos:
9086
- id: check-byte-order-marker
9187
exclude: ^autogenerated_graphql_client/
9288
- id: check-docstring-first
93-
exclude: ^autogenerated_graphql_client/
9489
- id: check-executables-have-shebangs
95-
exclude: ^autogenerated_graphql_client/
9690
- id: check-merge-conflict
97-
exclude: ^autogenerated_graphql_client/
9891
- id: check-yaml
99-
exclude: ^autogenerated_graphql_client/
10092
- id: end-of-file-fixer
101-
exclude: |
102-
(?x)(
103-
^autogenerated_graphql_client/|
104-
^queries.graphql|
105-
^schema.graphql
106-
)
10793
- id: pretty-format-json
108-
exclude: ^autogenerated_graphql_client/
10994
- id: mixed-line-ending
110-
exclude: ^autogenerated_graphql_client/
11195
- id: trailing-whitespace
112-
exclude: ^autogenerated_graphql_client/
11396

11497
- repo: https://github.com/dosisod/refurb
115-
rev: v1.15.0
98+
rev: v1.17.0
11699
hooks:
117100
- id: refurb
118101
exclude: |
119102
(?x)(
120103
^autogenerated_graphql_client/|
121-
^queries.graphql|
122-
^schema.graphql
123104
)
124105
125106
- repo: https://github.com/fsfe/reuse-tool

.reuse/dep5

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
22
Upstream-Name: OS2mo-amqp-trigger-job-function-configurator
33
Upstream-Contact: Magenta ApS <[email protected]>
44

5-
Files: poetry.* *poetry.lock autogenerated_graphql_client/*
5+
Files: poetry.* *poetry.lock job_function_configurator/autogenerated_graphql_client/*
66
Copyright: 2023 Magenta ApS <https://magenta.dk>
77
License: MPL-2.0

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ services:
1313
networks:
1414
- os2mo_default
1515
volumes:
16-
- ./job_function_configurator:/opt/app/
16+
- ./job_function_configurator:/app/job_function_configurator
1717
ports:
18-
- "8200:8000"
18+
- "8000:8000"
1919

2020
networks:
2121
os2mo_default:

docker.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2023 Magenta ApS <https://magenta.dk>
22
# SPDX-License-Identifier: MPL-2.0
33

4-
AMQP__URL="amqp://guest:guest@msg_broker:5672/"
4+
AMQP__URL="amqp://guest:guest@msg-broker:5672/"
55

66
MO_URL="http://mo"
77

autogenerated_graphql_client/__init__.py renamed to job_function_configurator/autogenerated_graphql_client/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22

33
from .async_base_client import AsyncBaseClient
44
from .base_model import BaseModel

autogenerated_graphql_client/async_base_client.py renamed to job_function_configurator/autogenerated_graphql_client/async_base_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22

33
import enum
44
import json

autogenerated_graphql_client/base_model.py renamed to job_function_configurator/autogenerated_graphql_client/base_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22

33
from typing import Any, Dict, Type, Union, get_args, get_origin
44

autogenerated_graphql_client/client.py renamed to job_function_configurator/autogenerated_graphql_client/client.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22
# Source: queries.graphql
33

44
from datetime import datetime
@@ -78,13 +78,14 @@ async def update_extension_field(
7878
self,
7979
uuid: UUID,
8080
from_date: datetime,
81+
to_date: Union[Optional[datetime], UnsetType] = UNSET,
8182
extension_3: Union[Optional[str], UnsetType] = UNSET,
8283
) -> UpdateExtensionFieldEngagementUpdate:
8384
query = gql(
8485
"""
85-
mutation UpdateExtensionField($uuid: UUID!, $from_date: DateTime!, $extension_3: String) {
86+
mutation UpdateExtensionField($uuid: UUID!, $from_date: DateTime!, $to_date: DateTime, $extension_3: String) {
8687
engagement_update(
87-
input: {uuid: $uuid, validity: {from: $from_date}, extension_3: $extension_3}
88+
input: {uuid: $uuid, validity: {from: $from_date, to: $to_date}, extension_3: $extension_3}
8889
) {
8990
uuid
9091
}
@@ -94,6 +95,7 @@ async def update_extension_field(
9495
variables: dict[str, object] = {
9596
"uuid": uuid,
9697
"from_date": from_date,
98+
"to_date": to_date,
9799
"extension_3": extension_3,
98100
}
99101
response = await self.execute(query=query, variables=variables)

autogenerated_graphql_client/enums.py renamed to job_function_configurator/autogenerated_graphql_client/enums.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22
# Source: schema.graphql
33

44
from enum import Enum

autogenerated_graphql_client/exceptions.py renamed to job_function_configurator/autogenerated_graphql_client/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22

33
from typing import Any, Dict, List, Optional, Union
44

autogenerated_graphql_client/get_engagement.py renamed to job_function_configurator/autogenerated_graphql_client/get_engagement.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22
# Source: queries.graphql
33

44
from datetime import datetime

autogenerated_graphql_client/input_types.py renamed to job_function_configurator/autogenerated_graphql_client/input_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22
# Source: schema.graphql
33

44
from datetime import datetime

autogenerated_graphql_client/scalars.py renamed to job_function_configurator/autogenerated_graphql_client/scalars.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22

33
from typing import Any, Callable, Dict
44

autogenerated_graphql_client/update_extension_field.py renamed to job_function_configurator/autogenerated_graphql_client/update_extension_field.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by ariadne-codegen on 2023-07-28 09:56
1+
# Generated by ariadne-codegen on 2023-08-29 12:26
22
# Source: queries.graphql
33

44
from uuid import UUID

job_function_configurator/depends.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
from fastapi import Depends
66
from ramqp.depends import from_context
77

8-
from autogenerated_graphql_client import GraphQLClient as _GraphQLClient
8+
from job_function_configurator.autogenerated_graphql_client import GraphQLClient as _GraphQLClient
99

1010
GraphQLClient = Annotated[_GraphQLClient, Depends(from_context("graphql_client"))]

job_function_configurator/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ramqp.mo import MORouter
99
from ramqp.mo import PayloadUUID
1010

11-
from autogenerated_graphql_client import GraphQLClient
11+
from job_function_configurator.autogenerated_graphql_client import GraphQLClient
1212
from job_function_configurator import depends
1313
from job_function_configurator.config import get_settings
1414
from job_function_configurator.log import setup_logging

job_function_configurator/process_events.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import structlog
66
from more_itertools import one
77

8-
from autogenerated_graphql_client import GraphQLClient
8+
from job_function_configurator.autogenerated_graphql_client import GraphQLClient
99
from job_function_configurator.config import get_settings
1010
from job_function_configurator.helper_functions import (
1111
check_for_blacklisted_engagement_job_function_user_keys,
@@ -39,10 +39,7 @@ async def process_engagement_events(
3939
engagement_uuid, settings.email_user_key_for_address_type
4040
)
4141

42-
if (
43-
engagement_object_parsed_as_model
44-
or engagement_object_parsed_as_model.objects is None
45-
):
42+
if len(engagement_object_parsed_as_model.objects) == 0:
4643
# No objects were found in the GraphQL payload - might be a termination.
4744
logger.info("Engagement objects are missing")
4845
return
@@ -60,6 +57,7 @@ async def process_engagement_events(
6057

6158
# Use the engagements current "from" date to avoid multiple entries in database.
6259
update_from_date = engagement_objects.validity.from_
60+
update_to_date = engagement_objects.validity.to
6361

6462
# Check whether job functions codes are in blacklist.
6563
job_function_user_key = engagement_objects.job_function.user_key
@@ -70,6 +68,7 @@ async def process_engagement_events(
7068
await mo.update_extension_field(
7169
engagement_uuid,
7270
update_from_date,
71+
update_to_date,
7372
settings.emtpy_content_for_extension_field_update,
7473
)
7574

@@ -90,7 +89,7 @@ async def process_engagement_events(
9089
)
9190
job_function_name_from_sd = engagement_objects.job_function.name
9291
await mo.update_extension_field(
93-
engagement_uuid, update_from_date, job_function_name_from_sd
92+
engagement_uuid, update_from_date, update_to_date, job_function_name_from_sd
9493
)
9594
# We should have passed the check for blacklisted job function codes (user keys)
9695
# at this point.
@@ -131,7 +130,7 @@ async def process_engagement_events(
131130
new_job_function = engagement_objects.extension_2
132131
# Make a mutation, write the contents of extension_2, to extension_x.
133132
await mo.update_extension_field(
134-
engagement_uuid, update_from_date, new_job_function
133+
engagement_uuid, update_from_date, update_to_date, new_job_function
135134
)
136135
logger.info(
137136
"An update with the contents of extension_2 was successfully made to"
@@ -142,7 +141,7 @@ async def process_engagement_events(
142141
# Make mutation, write what is the current job function name to the extension.
143142
job_function_name_from_sd = engagement_objects.job_function.name
144143
await mo.update_extension_field(
145-
engagement_uuid, update_from_date, job_function_name_from_sd
144+
engagement_uuid, update_from_date, update_to_date, job_function_name_from_sd
146145
)
147146
logger.info(
148147
"An update with the job function from SD was successfully made to"
@@ -154,7 +153,7 @@ async def process_engagement_events(
154153
# job functions name to the new extension.
155154
job_function_name_from_sd = engagement_objects.job_function.name
156155
await mo.update_extension_field(
157-
engagement_uuid, update_from_date, job_function_name_from_sd
156+
engagement_uuid, update_from_date, update_to_date, job_function_name_from_sd
158157
)
159158
logger.info(
160159
"An update with the job function from SD was successfully made to"

0 commit comments

Comments
 (0)