Skip to content

Commit

Permalink
Merge pull request #3 from PSNAppz/1.0
Browse files Browse the repository at this point in the history
Fix update API issue
  • Loading branch information
venky-ganapathy authored Nov 21, 2024
2 parents f908000 + 03ceb3a commit c616ef7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion openg2p-sr-celery-beat-producers/Dockerfile-git
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN python3 -m venv venv \
RUN python3 -m pip install \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-common \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-auth \
git+https://github.com/OpenG2P/openg2p-social-registry-bg-tasks@develop\#subdirectory=openg2p-sr-models \
git+https://github.com/OpenG2P/openg2p-social-registry-bg-tasks@1.0\#subdirectory=openg2p-sr-models \
./src

USER ${container_user}
Expand Down
18 changes: 14 additions & 4 deletions openg2p-sr-celery-workers/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
AUTH_URL=https://keycloak.openg2p.org/realms/master/protocol/openid-connect/token
AUTH_CLIENT_ID=client_id
AUTH_CLIENT_SECRET=client_secret
AUTH_GRANT_TYPE=client_credentials
SR_CELERY_WORKERS_DB_DBNAME: socialregistrydb
SR_CELERY_WORKERS_DB_USERNAME: socialregistryuser
SR_CELERY_WORKERS_DB_HOSTNAME: '172.29.8.235'
SR_CELERY_WORKERS_DB_PORT: 5432
SR_CELERY_WORKERS_CELERY_BROKER_URL: redis://{{ .Release.Name }}-redis-master:6379/0
SR_CELERY_WORKERS_CELERY_BACKEND_URL: redis://{{ .Release.Name }}-redis-master:6379/0
SR_CELERY_WORKERS_AUTH_URL: https://keycloak.openg2p.net/realms/master/protocol/openid-connect/token
SR_CELERY_WORKERS_AUTH_CLIENT_ID: openg2p-sr-loadtest
SR_CELERY_WORKERS_AUTH_CLIENT_SECRET: ""
SR_CELERY_WORKERS_AUTH_GRANT_TYPE: client_credentials
SR_CELERY_WORKERS_MOSIP_GET_UIN_URL: https://idgenerator.loadtest.openg2p.net/v1/idgenerator/uin
SR_CELERY_WORKERS_MOSIP_UPDATE_UIN_URL: https://idgenerator.loadtest.openg2p.net/v1/idgenerator/uin
SR_CELERY_WORKERS_MAX_ID_GENERATION_REQUEST_ATTEMPTS: 3
SR_CELERY_WORKERS_MAX_ID_GENERATION_UPDATE_ATTEMPTS: 3
2 changes: 1 addition & 1 deletion openg2p-sr-celery-workers/Dockerfile-git
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN python3 -m venv venv \
RUN python3 -m pip install \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-common \
git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-auth \
git+https://github.com/OpenG2P/openg2p-social-registry-bg-tasks@develop\#subdirectory=openg2p-sr-models \
git+https://github.com/OpenG2P/openg2p-social-registry-bg-tasks@1.0\#subdirectory=openg2p-sr-models \
./src

USER ${container_user}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def id_generation_update_worker(registrant_id: str):
f"No UIN found for registrant_id: {registrant_id} in res_partner"
)

uin = res_partner.ref_id

# Get OIDC token
access_token = OAuthTokenService.get_component().get_oauth_token()
_logger.info("Received access token")
Expand All @@ -62,33 +60,44 @@ def id_generation_update_worker(registrant_id: str):
"Cookie": f"Authorization={access_token}",
"Accept": "application/json",
}
current_datetime = datetime.utcnow()
formatted_datetime = (
current_datetime.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
)

# Call MOSIP Update UIN API to update status
update_payload = {
"id": "string",
"metadata": {},
"request": {"uin": uin, "status": "ASSIGNED"},
"requesttime": datetime.utcnow().isoformat(),
"request": {"uin": res_partner.ref_id, "status": "ASSIGNED"},
"requesttime": formatted_datetime,
"version": "string",
}
response = httpx.put(
_config.mosip_update_uin_url, json=update_payload, headers=headers
)
_logger.info(
f"Received response from MOSIP Update UIN API: {response.text}"
)
if response.status_code != 200:
raise Exception(
f"MOSIP Update UIN API call failed with status code {response.status_code}"
)

# Update queue entry statuses
# Status code is 200
if response.json().get("errors"):
raise Exception(
f"MOSIP Update UIN API call failed with error: {response.json().get('errors')}"
)

# Status is 200 and No errors then update queue entry statuses
queue_entry.number_of_attempts_update += 1
queue_entry.id_generation_update_status = IDGenerationUpdateStatus.COMPLETED
queue_entry.last_attempt_datetime = datetime.utcnow()
queue_entry.last_attempt_error_code_update = None
session.commit()

_logger.info(
f"ID generation update completed for registrant_id: {registrant_id}"
)
_logger.info(f"Mosip update completed for registrant_id: {registrant_id}")

except Exception as e:
error_message = f"Error during ID generation update for registrant_id {registrant_id}: {str(e)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ class G2PQueIDGeneration(BaseORMModelWithTimes):
class ResPartner(BaseORMModel):
__tablename__ = "res_partner"

id: mapped_column[int] = mapped_column(primary_key=True)
id = mapped_column(Integer, primary_key=True)
ref_id = mapped_column(String)
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class G2PQueIDGenerationModel(BaseModel):


class ResPartnerModel(BaseModel):
registrant_id: str
registrant_id: int
ref_id: Optional[str]

0 comments on commit c616ef7

Please sign in to comment.