Skip to content
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

Add facility to sync functions #126

Merged
merged 13 commits into from
Jan 9, 2025

Conversation

stuartcampbell
Copy link
Collaborator

Exposed the facility name to various functions and endpoints.

I have not extensively tested this yet.

@stuartcampbell stuartcampbell self-assigned this Dec 20, 2024
@JunAishima
Copy link
Contributor

I've tried pushing a commit to your branch but could not do so.

Here is the diff:

diff --git a/src/nsls2api/api/v1/facility_api.py b/src/nsls2api/api/v1/facility_api.py
index 89002d0..4bd2f02 100644
--- a/src/nsls2api/api/v1/facility_api.py
+++ b/src/nsls2api/api/v1/facility_api.py
@@ -69,7 +69,7 @@ async def get_proposals_for_cycle(facility: FacilityName, cycle: str):
             status_code=501,
         )
 
-    proposal_list = await proposal_service.fetch_proposals_for_cycle(cycle)
+    proposal_list = await proposal_service.fetch_proposals_for_cycle(cycle, facility)
     if proposal_list is None:
         return fastapi.responses.JSONResponse(
             {"error": f"No proposals were found for cycle {cycle}"},

@JunAishima
Copy link
Contributor

JunAishima commented Dec 23, 2024

Also looks like the stats need to be updated - currently only handling nsls2, though we could fix this separately.

Copy link
Contributor

@JunAishima JunAishima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please clarify how the facility name is going to be set in sync_proposals_for_cycle - will it be added to the URL, or will it need to be part of the request? or will another method be required?

src/nsls2api/api/v1/jobs_api.py Outdated Show resolved Hide resolved
nmaytan
nmaytan previously requested changes Jan 7, 2025
src/nsls2api/services/background_service.py Outdated Show resolved Hide resolved
@nmaytan
Copy link
Collaborator

nmaytan commented Jan 7, 2025

Are proposals ID guaranteed by PASS to be unique across facilities? This obviously could impact other things - pardon my ignorance about this detail.

@JunAishima
Copy link
Contributor

Are proposals ID guaranteed by PASS to be unique across facilities? This obviously could impact other things - pardon my ignorance about this detail.

My understanding is that the proposal IDs are a common pool so there could be proposal IDs that are the same between facilities, but only when the proposal will potentially use multiple facilities. I also asked this question before as it is not obvious from our code or the PASS API documentation.

@JunAishima
Copy link
Contributor

JunAishima commented Jan 8, 2025

Diff to fix the issue with text when synchronizing proposals_for_cycle:

diff --git a/src/nsls2api/services/background_service.py b/src/nsls2api/services/background_service.py
index e131a62..aac5e87 100644
--- a/src/nsls2api/services/background_service.py
+++ b/src/nsls2api/services/background_service.py
@@ -130,7 +130,7 @@ async def worker_function():
                     )
                 case JobActions.synchronize_proposals_for_cycle:
                     logger.info(
-                        f"Processing job {job.id} to synchronize proposals for the {job.sync_parameters.facility} facilities cycle {job.sync_parameters.cycle} (from {job.sync_parameters.sync_source})."
+                        f"Processing job {job.id} to synchronize proposals for the {job.sync_parameters.facility} facility, cycle {job.sync_parameters.cycle} (from {job.sync_parameters.sync_source})."
                     )
                     await sync_service.worker_synchronize_proposals_for_cycle_from_pass(
                         job.sync_parameters.cycle, job.sync_paramters.facility

Copy link
Contributor

@JunAishima JunAishima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added suggested change to background_service.py to fix awkward text

src/nsls2api/services/background_service.py Outdated Show resolved Hide resolved
@nmaytan
Copy link
Collaborator

nmaytan commented Jan 8, 2025

My understanding is that the proposal IDs are a common pool so there could be proposal IDs that are the same between facilities, but only when the proposal will potentially use multiple facilities. I also asked this question before as it is not obvious from our code or the PASS API documentation.

In this case, hopefully the proposal is just one singular entity in PASS? i.e. not two entities that just have the same proposal ID but may have differing "metadata" otherwise. Some partial evidence of this is that when you retrieve a proposal through nsls2api, there is no facility field (not sure if that is reflective of its state in PASS)

@JunAishima
Copy link
Contributor

one last suggestion to fix the check for facility name in get_proposals_for_cycle():

diff --git a/src/nsls2api/api/v1/facility_api.py b/src/nsls2api/api/v1/facility_api.py
index 4bd2f02..c4e066a 100644
--- a/src/nsls2api/api/v1/facility_api.py
+++ b/src/nsls2api/api/v1/facility_api.py
@@ -62,7 +62,7 @@ async def get_facility_cycles(facility: FacilityName):
     include_in_schema=True,
 )
 async def get_proposals_for_cycle(facility: FacilityName, cycle: str):
-    if facility.name != "nsls2":
+    if facility.name not in ("nsls2", "lbms"):
         # TODO: Add other facilities
         return fastapi.responses.JSONResponse(
             {"message": f"Not implemented for the {facility.name} facility."},

@stuartcampbell
Copy link
Collaborator Author

Are proposals ID guaranteed by PASS to be unique across facilities? This obviously could impact other things - pardon my ignorance about this detail.

I've checked this in the past with the PASS developers and yes - all proposal ids are unique across all of PASS irrespective of what facility they are for.

@stuartcampbell stuartcampbell dismissed nmaytan’s stale review January 9, 2025 21:33

I made the change that was suggested (the facilities->facility)

This really needs a rethink - but for now just add the LBMS stats.
Copy link
Contributor

@JunAishima JunAishima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last minor spelling change!

src/nsls2api/services/background_service.py Outdated Show resolved Hide resolved
Co-authored-by: Jun Aishima <jaishima@bnl.gov>
@stuartcampbell
Copy link
Collaborator Author

Self merging as changes have been approved by @JunAishima

@stuartcampbell stuartcampbell merged commit b627872 into NSLS2:main Jan 9, 2025
4 checks passed
@stuartcampbell stuartcampbell deleted the add-facility-to-sync branch January 9, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants