-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fixed proposal membership query so that production API server is used #361
Open
vshekar
wants to merge
1
commit into
NSLS-II:master
Choose a base branch
from
vshekar:update-NSLS-2-API-calls
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ def __init__(self, parent: "ControlMain"): | |
self.customContextMenuRequested.connect(self.openMenu) | ||
self.setStyleSheet("QTreeView::item::hover{background-color: #999966;}") | ||
# Keeps track of whether the user is part of a proposal | ||
self.proposal_membership = {} | ||
self.proposal_membership = set() | ||
|
||
def openMenu(self, position): | ||
indexes = self.selectedIndexes() | ||
|
@@ -272,19 +272,19 @@ def add_samples_to_puck_tree( | |
self.parent.row_clicked(current_index) | ||
|
||
def is_proposal_member(self, proposal_id) -> bool: | ||
# Check if the user running LSDC is part of the sample's proposal | ||
if proposal_id not in self.proposal_membership: | ||
r = requests.get(f"{os.environ['NSLS2_API_URL']}/proposal/{proposal_id}") | ||
# Check if the user running LSDC is part of the sample's proposal | ||
# If the proposal_membership set is empty get data from API (Use prod API) | ||
# This way API is only polled once when GUI starts | ||
if not self.proposal_membership: | ||
r = requests.get(f"{os.environ['NSLS2_API_URL']}/v1/data-session/{getpass.getuser()}") | ||
r.raise_for_status() | ||
response = r.json() | ||
if "users" in response and getpass.getuser() in [ | ||
user["username"] for user in response["users"] if "username" in user | ||
]: | ||
self.proposal_membership[proposal_id] = True | ||
else: | ||
logger.info(f"Users not found in response: {response}") | ||
self.proposal_membership[proposal_id] = False | ||
return self.proposal_membership[proposal_id] | ||
for session in response.get("data_sessions", []): | ||
# Assuming data_sessions has values of the form "pass-123456" | ||
proposal = session.split("-")[1] | ||
self.proposal_membership.add(proposal) | ||
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. actually, this won't take care of case 2 above, since you only add proposals, never remove. so would require clearing all proposals and re-creating the set. |
||
print(f"Updated proposal_membership for {getpass.getuser()}: {self.proposal_membership}") | ||
return str(proposal_id) in self.proposal_membership | ||
|
||
def create_request_item(self, request) -> QtGui.QStandardItem: | ||
col_item = QtGui.QStandardItem( | ||
|
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.
so if the proposal info gets updated while the user is running the program, they would need to shut down. this should only be a problem if they weren't on the visit originally. possibly an issue if they are removed during the current visit.
we could maybe force the user to reload info in situation 1, but what about situation 2 (no incentive to reload)? a timed retrieval of the info?
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.
Few reasons why I didn't address situation 2:
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.
the case of somebody being removed from a proposal should be handled - while it won't be common, it's possible this could happen, logically.
any querying of the API server should be on the minutes scale - we don't need to boot anybody immediately, and there is already a lag period of data coming from the PASS API into the NSLS2 API.
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.
So what do you suggest the interval should be?
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.
check every 5 mins. any more is a waste of cycles for doing this checking, any less, and the user would have a lot of time to do things after being removed.