Skip to content

Commit

Permalink
min-max on percent calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Mar 14, 2024
1 parent 80f3d4c commit a4e8acf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Settings(BaseSettings):
pflink_mongodb: MongoDsn = 'mongodb://localhost:27017'
version: str = "3.9.5"
version: str = "3.9.6"
mongo_username: str = "admin"
mongo_password: str = "admin"
log_level: str = "DEBUG"
Expand Down
45 changes: 23 additions & 22 deletions app/controllers/subprocesses/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
import argparse
import json
import logging
import pprint
import random
import requests
import time
import pprint
from logging.config import dictConfig

import requests

from app import log
from app.models.workflow import (
State,
WorkflowRequestSchema,
WorkflowDBSchema,
WorkflowStatusResponseSchema,
Error,
)
from app.controllers.subprocesses.subprocess_helper import get_process_count
from app.controllers.subprocesses.utils import (
query_to_dict,
dict_to_hash,
update_workflow,
retrieve_workflow,
get_cube_url_from_pfdcm,
substitute_dicom_tags,
Expand All @@ -29,8 +24,14 @@
update_workflow_response,
update_status_flag,
)
from app.models.workflow import (
State,
WorkflowRequestSchema,
WorkflowDBSchema,
WorkflowStatusResponseSchema,
Error,
)

from app.controllers.subprocesses.subprocess_helper import get_process_count
dictConfig(log.log_config)
logger = logging.getLogger('pflink-logger')
d = {'workername': 'STATUS_MGR', 'log_color': "\33[36m", 'key': ""}
Expand Down Expand Up @@ -75,14 +76,14 @@ def update_workflow_progress(response: WorkflowStatusResponseSchema):
Update the overall workflow progress of a workflow from its current
workflow state.
"""
MAX_STATE = 6
MAX_STATE = 7
index = 0
for elem in State:
if response.workflow_state == elem:
state_progress = int(response.state_progress.replace('%',''))

response.workflow_progress_perc = max(response.workflow_progress_perc,
__progress_percent(index,MAX_STATE,state_progress))
response.workflow_progress_perc = min(100, max(response.workflow_progress_perc,
__progress_percent(index,MAX_STATE,state_progress)))
index += 1
return response

Expand Down Expand Up @@ -264,8 +265,8 @@ def _parse_response(
"""
# status = WorkflowStatusResponseSchema()
# reset status of any stale errors or states
# status.status = True
# status.error = ""
status.status = True
status.error = ""

pfdcm_has_error = pfdcm_response.get("error")
cube_has_error = cube_response.get("error")
Expand Down Expand Up @@ -330,12 +331,12 @@ def _parse_response(
status.status = False
return status

else:
if status.feed_name:
status.workflow_state = State.FEED_DELETED
status.status = False
status.error = Error.feed_deleted.value
status.state_progress = "0%"
# else:
# if status.feed_name:
# status.workflow_state = State.FEED_DELETED
# status.status = False
# status.error = Error.feed_deleted.value
# status.state_progress = "0%"
return status


Expand Down
7 changes: 5 additions & 2 deletions app/controllers/subprocesses/wf_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,15 @@ def analysis_retry(workflow: WorkflowDBSchema,db_key: str):
if workflow.service_retry < 5 and not workflow.response.status and workflow.response.workflow_state == State.ANALYZING:
logger.warning(f"Retrying request.{5 - workflow.service_retry}/5 retries left.", extra=d)
logger.warning(f"Setting feed requested status to False in the DB", extra=d)
workflow.service_retry += 1
workflow.feed_requested = False
if workflow.feed_requested:
workflow.service_retry += 1
workflow.feed_requested = False
workflow.feed_id_generated = ""
workflow.started = False
workflow.response.workflow_state = State.REGISTERING
workflow.response.state_progress = "100%"
workflow.response.feed_id = ""
workflow.response.feed_name = ""
workflow.response.workflow_progress_perc = 0
workflow.response.error = ""
workflow.response.status = True
Expand Down

0 comments on commit a4e8acf

Please sign in to comment.