Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EP Merge: Fixed issue with created_at being incorrectly set. #2695

Merged
merged 7 commits into from
Mar 2, 2024
Merged
6 changes: 5 additions & 1 deletion domain-ee/ee-ep-merge-app/src/python_src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from contextlib import asynccontextmanager
from typing import Annotated
from uuid import UUID, uuid4
from datetime import datetime

import uvicorn
from fastapi import BackgroundTasks, FastAPI, HTTPException, Query, Request, status
Expand Down Expand Up @@ -104,8 +105,11 @@ async def merge_claims(request: Request, merge_request: MergeEndProductsRequest,
return JSONResponse(status_code=500, content=jsonable_encoder({"method": "POST", "url": str(request.url), "errors": errors}))

job_id = uuid4()
now = datetime.now()

merge_job = MergeJob(job_id=job_id, pending_claim_id=merge_request.pending_claim_id, ep400_claim_id=merge_request.ep400_claim_id)
merge_job = MergeJob(
job_id=job_id, pending_claim_id=merge_request.pending_claim_id, ep400_claim_id=merge_request.ep400_claim_id, created_at=now, updated_at=now
)
JOB_STORE.submit_merge_job(merge_job)

logging.info(
Expand Down
4 changes: 3 additions & 1 deletion domain-ee/ee-ep-merge-app/src/python_src/graph_export.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from uuid import uuid4

import pydot
Expand Down Expand Up @@ -119,7 +120,8 @@ def __call__(self):


def generate_graph(main_event):
job = MergeJob(job_id=uuid4(), pending_claim_id=1, ep400_claim_id=2)
now = datetime.now()
job = MergeJob(job_id=uuid4(), pending_claim_id=1, ep400_claim_id=2, created_at=now, updated_at=now)

#
graph = DotGraphMachine(EpMergeMachine(job, main_event))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import model.merge_job
from pydantic import BaseModel, ConfigDict, conint
from typing_extensions import ClassVar
from util.custom_enum import StrEnum


Expand Down Expand Up @@ -38,16 +37,14 @@ def __str__(self):


class MergeJob(BaseModel):
_init_time: ClassVar[datetime] = datetime.now()

job_id: UUID
pending_claim_id: conint(strict=True)
ep400_claim_id: conint(strict=True)
state: JobState = JobState.PENDING
error_state: JobState | None = None
messages: list[Any] | None = None
created_at: datetime = _init_time
updated_at: datetime = _init_time
created_at: datetime
updated_at: datetime
nanotone marked this conversation as resolved.
Show resolved Hide resolved

model_config = ConfigDict(from_attributes=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def on_completed(self, event):
f"job_id={self.job.job_id} "
f"pending_claim_id={self.job.pending_claim_id} "
f"ep400_claim_id={self.job.ep400_claim_id} "
f"state={self.job.state}"
f"state={self.job.state} "
f"job_duration_seconds={job_duration}"
)

Expand Down
4 changes: 3 additions & 1 deletion domain-ee/ee-ep-merge-app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import uuid
from unittest.mock import MagicMock
from datetime import datetime

import pytest
from fastapi.testclient import TestClient
Expand All @@ -22,4 +23,5 @@ def db():

@pytest.fixture
def merge_job():
return schema.MergeJob(job_id=uuid.uuid4(), pending_claim_id=1, ep400_claim_id=2, state="PENDING")
now = datetime.now()
return schema.MergeJob(job_id=uuid.uuid4(), pending_claim_id=1, ep400_claim_id=2, state="PENDING", created_at=now, updated_at=now)
3 changes: 3 additions & 0 deletions domain-ee/ee-ep-merge-app/tests/service/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import uuid
from unittest.mock import ANY, AsyncMock, call
from datetime import datetime

import pytest
from src.python_src.config import EP_MERGE_SPECIAL_ISSUE_CODE
Expand Down Expand Up @@ -32,6 +33,8 @@
PENDING_CLAIM_ID = 1
PENDING_CLAIM_EP_CODE = "010"
EP400_CLAIM_ID = 2
CREATED_AT = datetime.now()
UPDATED_AT = CREATED_AT
cancel_reason = CANCELLATION_REASON_FORMAT.format(ep_code=PENDING_CLAIM_EP_CODE, claim_id=PENDING_CLAIM_ID)

RESPONSE_DIR = os.path.abspath('./tests/responses')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
EP400_CLAIM_ID,
JOB_ID,
PENDING_CLAIM_ID,
CREATED_AT,
UPDATED_AT,
add_claim_note_200,
add_claim_note_req,
assert_metrics_called,
Expand Down Expand Up @@ -56,7 +58,9 @@

@pytest.fixture
def machine():
return EpMergeMachine(MergeJob(job_id=JOB_ID, pending_claim_id=PENDING_CLAIM_ID, ep400_claim_id=EP400_CLAIM_ID))
return EpMergeMachine(
MergeJob(job_id=JOB_ID, pending_claim_id=PENDING_CLAIM_ID, ep400_claim_id=EP400_CLAIM_ID, created_at=CREATED_AT, updated_at=UPDATED_AT)
)


def test_constructor():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
EP400_CLAIM_ID,
JOB_ID,
PENDING_CLAIM_ID,
CREATED_AT,
UPDATED_AT,
add_claim_note_200,
add_claim_note_req,
get_ep400_contentions_200,
Expand All @@ -30,7 +32,14 @@
@pytest.fixture
def machine():
return EpMergeMachine(
MergeJob(job_id=JOB_ID, pending_claim_id=PENDING_CLAIM_ID, ep400_claim_id=EP400_CLAIM_ID, state=JobState.ADD_CLAIM_NOTE_TO_EP400),
MergeJob(
job_id=JOB_ID,
pending_claim_id=PENDING_CLAIM_ID,
ep400_claim_id=EP400_CLAIM_ID,
state=JobState.ADD_CLAIM_NOTE_TO_EP400,
created_at=CREATED_AT,
updated_at=UPDATED_AT,
),
Workflow.RESUME_ADD_NOTE,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
EP400_CLAIM_ID,
JOB_ID,
PENDING_CLAIM_ID,
CREATED_AT,
UPDATED_AT,
add_claim_note_200,
add_claim_note_req,
cancel_claim_200,
Expand Down Expand Up @@ -41,7 +43,14 @@
@pytest.fixture
def machine():
return EpMergeMachine(
MergeJob(job_id=JOB_ID, pending_claim_id=PENDING_CLAIM_ID, ep400_claim_id=EP400_CLAIM_ID, state=JobState.CANCEL_EP400_CLAIM),
MergeJob(
job_id=JOB_ID,
pending_claim_id=PENDING_CLAIM_ID,
ep400_claim_id=EP400_CLAIM_ID,
state=JobState.CANCEL_EP400_CLAIM,
created_at=CREATED_AT,
updated_at=UPDATED_AT,
),
Workflow.RESUME_CANCEL_EP400,
)

Expand Down