Skip to content

Commit

Permalink
Fixed issue with created_at being incorrectly set.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfitchett committed Feb 29, 2024
1 parent 0f0c675 commit 78c8d16
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 12 deletions.
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
7 changes: 2 additions & 5 deletions domain-ee/ee-ep-merge-app/src/python_src/schema/merge_job.py
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

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

0 comments on commit 78c8d16

Please sign in to comment.