-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/15 create flow run log service #24
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
76e690f
Created functionality to record the user flow logs
Sachinbisht27 83ae8ff
Created functionality to record the user flow logs
Sachinbisht27 f34923e
Created functionality to record the user flow logs
Sachinbisht27 c597493
added suggested changes
Sachinbisht27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .flow_run_log_service import * | ||
from .user_creation_service import * | ||
from .user_indicator_response_service import * | ||
from .webhook_transaction_log_service import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||||||||||||||||||||
from datetime import datetime, timedelta | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
from api import models | ||||||||||||||||||||||||
from api.utils import db_utils | ||||||||||||||||||||||||
from api.utils.loggingutils import logger | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
class FlowRunLogService: | ||||||||||||||||||||||||
def __init__(self, user): | ||||||||||||||||||||||||
self.user = user | ||||||||||||||||||||||||
self.class_model = models.UserFlows | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
def create_user_flow_log(self, json_data): | ||||||||||||||||||||||||
try: | ||||||||||||||||||||||||
flow_uuid = json_data.get("flow_uuid") | ||||||||||||||||||||||||
flow_name = json_data.get("flow_name") | ||||||||||||||||||||||||
flow_type = json_data.get("flow_type") | ||||||||||||||||||||||||
flow_completed = json_data.get("flow_completed") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
today_flow_log = self.class_model.query.get_by_flow_uuid_and_phone( | ||||||||||||||||||||||||
flow_uuid, self.user.phone | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if not today_flow_log: | ||||||||||||||||||||||||
user_flow_log = self.create_log(flow_uuid, flow_name, flow_type) | ||||||||||||||||||||||||
elif today_flow_log and flow_completed: | ||||||||||||||||||||||||
user_flow_log = self.update_log(today_flow_log) | ||||||||||||||||||||||||
else: | ||||||||||||||||||||||||
user_flow_log = None | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
return user_flow_log | ||||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||||
logger.error( | ||||||||||||||||||||||||
f"Error while creating new user flow log. json data: {json_data}." | ||||||||||||||||||||||||
f"Error message: {e}" | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
raise | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
def create_log(self, flow_uuid, flow_name, flow_type): | ||||||||||||||||||||||||
user_flow_log = self.class_model( | ||||||||||||||||||||||||
user_id=self.user.id, | ||||||||||||||||||||||||
user_phone=self.user.phone, | ||||||||||||||||||||||||
flow_uuid=flow_uuid, | ||||||||||||||||||||||||
flow_name=flow_name, | ||||||||||||||||||||||||
flow_type=flow_type, | ||||||||||||||||||||||||
flow_run_status=self.class_model.FlowRunStatus.IN_PROGRESS, | ||||||||||||||||||||||||
flow_start_time=datetime.utcnow() + timedelta(minutes=330), | ||||||||||||||||||||||||
is_active=True, | ||||||||||||||||||||||||
) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
db_utils.save(user_flow_log) | ||||||||||||||||||||||||
logger.info(f"Created a user flow log for phone number {self.user.phone}.") | ||||||||||||||||||||||||
return user_flow_log | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
def update_log(self, today_flow_log): | ||||||||||||||||||||||||
today_flow_log.flow_run_status = self.class_model.FlowRunStatus.COMPLETED | ||||||||||||||||||||||||
today_flow_log.flow_end_time = datetime.utcnow() + timedelta(minutes=330) | ||||||||||||||||||||||||
today_flow_log.is_active = False | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
db_utils.save(today_flow_log) | ||||||||||||||||||||||||
logger.info(f"Updated user flow log for phone number {self.user.phone}.") | ||||||||||||||||||||||||
return today_flow_log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is gonna take more resources as the table grows. Can we find possibilities to configure index for these two columns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can take it seperately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added indexing in the flow uuid column as well.