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

Fix pass service calls with facility #132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/nsls2api/api/v1/jobs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,35 @@ async def sync_dataadmins(request: Request) -> BackgroundJob:
dependencies=[Depends(get_current_user)],
include_in_schema=SYNC_ROUTES_IN_SCHEMA,
tags=["sync"],
deprecated=True
)
async def sync_proposal(request: Request, proposal_id: str) -> BackgroundJob:
sync_params = JobSyncParameters(proposal_id=proposal_id)
async def sync_proposal(
request: Request, proposal_id: str, facility: FacilityName = FacilityName.nsls2
) -> BackgroundJob:
sync_params = JobSyncParameters(proposal_id=proposal_id, facility=facility)
job = await background_service.create_background_job(
JobActions.synchronize_proposal,
sync_parameters=sync_params,
)
return job


@router.get(
"/sync/facility/{facility}/proposal/{proposal_id}",
dependencies=[Depends(get_current_user)],
include_in_schema=SYNC_ROUTES_IN_SCHEMA,
tags=["sync"],
)
async def sync_facility_proposal(
request: Request, facility: FacilityName, proposal_id: str
) -> BackgroundJob:
sync_params = JobSyncParameters(proposal_id=proposal_id, facility=facility)
job = await background_service.create_background_job(
JobActions.synchronize_proposal,
sync_parameters=sync_params,
)
return job

@router.get(
"/sync/proposal/types/{facility}",
include_in_schema=SYNC_ROUTES_IN_SCHEMA,
Expand Down
4 changes: 2 additions & 2 deletions src/nsls2api/services/background_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ async def worker_function():
)
case JobActions.synchronize_proposal:
logger.info(
f"Processing job {job.id} to synchronize proposal {job.sync_parameters.proposal_id} (from {job.sync_parameters.sync_source})."
f"Processing job {job.id} to synchronize proposal {job.sync_parameters.proposal_id} for the {job.sync_parameters.facility} facility (from {job.sync_parameters.sync_source})."
)
await sync_service.worker_synchronize_proposal_from_pass(
job.sync_parameters.proposal_id
job.sync_parameters.proposal_id, job.sync_parameters.facility
)
case JobActions.synchronize_proposals_for_cycle:
logger.info(
Expand Down
14 changes: 7 additions & 7 deletions src/nsls2api/services/sync_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,20 @@ async def worker_synchronize_proposal_types_from_pass(
)


async def synchronize_proposal_from_pass(proposal_id: str) -> None:
async def synchronize_proposal_from_pass(proposal_id: str, facility_name: FacilityName = FacilityName.nsls2) -> None:
beamline_list = []
user_list = []
saf_list = []

try:
pass_proposal: PassProposal = await pass_service.get_proposal(proposal_id)
pass_proposal: PassProposal = await pass_service.get_proposal(proposal_id, facility_name)
except pass_service.PassException as error:
error_message = f"Error retrieving proposal {proposal_id} from PASS"
logger.exception(error_message)
raise Exception(error_message) from error

# Get the SAFs for this proposal
pass_saf_list: list[PassSaf] = await pass_service.get_saf_from_proposal(proposal_id)
pass_saf_list: list[PassSaf] = await pass_service.get_saf_from_proposal(proposal_id, facility_name)
for saf in pass_saf_list:
saf_beamline_list = []
for resource in saf.Resources:
Expand Down Expand Up @@ -351,10 +351,10 @@ async def update_proposals_with_cycle(
logger.warning(error)


async def worker_synchronize_proposal_from_pass(proposal_id: str) -> None:
async def worker_synchronize_proposal_from_pass(proposal_id: str, facility: FacilityName = FacilityName.nsls2) -> None:
start_time = datetime.datetime.now()

await synchronize_proposal_from_pass(proposal_id)
await synchronize_proposal_from_pass(proposal_id, facility)

time_taken = datetime.datetime.now() - start_time
logger.info(
Expand All @@ -378,7 +378,7 @@ async def worker_synchronize_proposals_for_cycle_from_pass(

for proposal_id in proposals:
logger.info(f"Synchronizing proposal {proposal_id}.")
await synchronize_proposal_from_pass(proposal_id)
await synchronize_proposal_from_pass(proposal_id, facility_name)

commissioning_proposals: list[
PassProposal
Expand All @@ -390,7 +390,7 @@ async def worker_synchronize_proposals_for_cycle_from_pass(
)
for proposal in commissioning_proposals:
logger.info(f"Synchronizing commissioning proposal {proposal.Proposal_ID}.")
await synchronize_proposal_from_pass(str(proposal.Proposal_ID))
await synchronize_proposal_from_pass(str(proposal.Proposal_ID), facility_name)

# Now update the cycle information for each proposal
await update_proposals_with_cycle(cycle, facility_name=facility_name)
Expand Down
Loading