Skip to content

Commit

Permalink
Merge pull request #518 from gemini-hlsw/GSCHED-727
Browse files Browse the repository at this point in the history
Changed program_file to programs_list
  • Loading branch information
dngomez authored Oct 22, 2024
2 parents aabc543 + 410afa6 commit 6cd1e58
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
7 changes: 5 additions & 2 deletions scheduler/core/programprovider/ocs/ocsprogramprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ def ocs_program_data(program_list: Optional[bytes] = None) -> Iterable[dict]:
try:
# Try to read the file and create a frozenset from its lines
if program_list:
list_file = program_list
if isinstance(program_list, List):
id_frozenset = frozenset(p.strip() for p in program_list if p.strip() and p.strip()[0] != '#')
return read_ocs_zipfile(DEFAULT_OCS_DATA_PATH, id_frozenset)
else:
list_file = program_list
else:
list_file = DEFAULT_PROGRAM_ID_PATH

if isinstance(program_list, bytes):
file = program_list.decode('utf-8')
id_frozenset = frozenset(f.strip() for f in file.split('\n') if f.strip() and f.strip()[0] != '#')

else:
with list_file.open('r') as file:
id_frozenset = frozenset(line.strip() for line in file if line.strip() and line.strip()[0] != '#')
Expand Down
2 changes: 1 addition & 1 deletion scheduler/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def build(self) -> SCP:
semesters=self.params.semesters,
with_redis=True,
blueprint=Blueprints.collector,
program_list=self.params.program_file)
program_list=self.params.programs_list)

selector = builder.build_selector(collector=collector,
num_nights_to_schedule=self.params.num_nights_to_schedule,
Expand Down
4 changes: 2 additions & 2 deletions scheduler/engine/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from dataclasses import dataclass, field
from datetime import datetime
from typing import final, Optional, FrozenSet
from typing import final, Optional, FrozenSet, List

from astropy.time import Time
from lucupy.minimodel import Site, ALL_SITES, Semester, NightIndex
Expand All @@ -27,7 +27,7 @@ class SchedulerParameters:
ranker_parameters: RankerParameters = field(default_factory=RankerParameters)
semester_visibility: bool = True
num_nights_to_schedule: Optional[int] = None
program_file: Optional[str] = None
programs_list: Optional[List[str]] = None

def __post_init__(self):
self.semesters = frozenset([Semester.find_semester_from_date(self.start.datetime),
Expand Down
2 changes: 1 addition & 1 deletion scheduler/graphql_mid/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CreateNewScheduleInput:
met_power: Optional[float] = 1.0
vis_power: Optional[float] = 1.0
wha_power: Optional[float] = 1.0
program_file: Optional[Upload] = None
programs: List[str]


@strawberry.input
Expand Down
14 changes: 5 additions & 9 deletions scheduler/graphql_mid/schema.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Copyright (c) 2016-2024 Association of Universities for Research in Astronomy, Inc. (AURA)
# For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause
import asyncio
import os
import sys
from datetime import datetime
from typing import List, AsyncGenerator, Dict

import strawberry # noqa
from astropy.time import Time
from redis import asyncio as aioredis
from lucupy.minimodel.site import Site

from scheduler.core.components.ranker import RankerParameters
Expand Down Expand Up @@ -58,17 +54,18 @@ async def schedule(self, schedule_id: str, new_schedule_input: CreateNewSchedule
new_schedule_input.met_power,
new_schedule_input.vis_power,
new_schedule_input.wha_power)
file = None
if new_schedule_input.program_file:
file = await new_schedule_input.program_file.read()
programs_list = None
if new_schedule_input.programs:
if len(new_schedule_input.programs) > 0:
programs_list = new_schedule_input.programs

params = SchedulerParameters(start, end,
new_schedule_input.sites,
new_schedule_input.mode,
ranker_params,
new_schedule_input.semester_visibility,
new_schedule_input.num_nights_to_schedule,
file)
programs_list)

_logger.info(f"Run ID: {schedule_id}\n{params}")

Expand All @@ -83,7 +80,6 @@ async def schedule(self, schedule_id: str, new_schedule_input: CreateNewSchedule
await queue.put(task)
return f'Plan is on the queue! for {schedule_id}'


@strawberry.type
class Subscription:
@strawberry.subscription
Expand Down

0 comments on commit 6cd1e58

Please sign in to comment.