Skip to content

Commit

Permalink
Config to cloud (#1260)
Browse files Browse the repository at this point in the history
* Config to cloud

* Change when the config is sent to the cloud.

* * Use `json.loads` instead of `from_json` so we don't create astropy objects.

Tested on PAN018
  • Loading branch information
wtgee authored May 8, 2024
1 parent d163796 commit 4f8bed7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/panoptes/pocs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ def __init__(self, config_host=None, config_port=None, *args, **kwargs):

PAN_DB_OBJ = PanDB(db_name=db_name, storage_dir=db_folder, db_type=db_type)

# Insert the current config into the DB since we just set it up. This will also
# send to the cloud (if enabled).
PAN_DB_OBJ.insert_current('config', self.get_config(), store_permanently=False)

self.db = PAN_DB_OBJ

def get_config(self, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions src/panoptes/pocs/utils/cli/network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import stat
import time
Expand All @@ -9,7 +10,6 @@
from google.cloud import firestore
from google.cloud import storage
from panoptes.utils.config.client import set_config, get_config
from panoptes.utils.serializers import from_json
from rich import print
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
Expand Down Expand Up @@ -111,7 +111,7 @@ def handleEvent(event):
return

try:
record = from_json(Path(event.src_path).read_text())
record = json.loads(Path(event.src_path).read_text())
collection = record['type']

# Get the "current" record and collections refs.
Expand Down
42 changes: 26 additions & 16 deletions src/panoptes/pocs/utils/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@


@app.callback()
def common(context: typer.Context,
simulator: List[str] = typer.Option(None, '--simulator', '-s', help='Simulators to load'),
cloud_logging: bool = typer.Option(False, '--cloud-logging', '-c', help='Enable cloud logging'),
):
def common(
context: typer.Context,
simulator: List[str] = typer.Option(None, '--simulator', '-s', help='Simulators to load'),
cloud_logging: bool = typer.Option(False, '--cloud-logging', '-c', help='Enable cloud logging'),
):
context.obj = [simulator, cloud_logging]


Expand Down Expand Up @@ -54,6 +55,14 @@ def get_pocs(context: typer.Context):
logger = get_logger(cloud_logging_level='DEBUG')

pocs = POCS.from_config(simulators=simulators)

pocs.logger.debug(f'POCS created from config')
pocs.logger.debug(f'Sending POCS config to cloud')
try:
pocs.db.insert_current('config', pocs.get_config())
except Exception as e:
pocs.logger.warning(f'Unable to send config to cloud: {e}')

pocs.initialize()

return pocs
Expand All @@ -80,18 +89,19 @@ def run_auto(context: typer.Context) -> None:


@app.command(name='alignment')
def run_alignment(context: typer.Context,
coords: List[str] = typer.Option(
None, '--coords', '-c',
help='Alt/Az coordinates to use, e.g. 40,120'
),
exptime: float = typer.Option(30.0, '--exptime', '-e', help='Exposure time in seconds.'),
num_exposures: int = typer.Option(
5, '--num-exposures', '-n',
help='Number of exposures per coordinate.'
),
field_name: str = typer.Option('PolarAlignment', '--field-name', '-f', help='Name of field.'),
) -> None:
def run_alignment(
context: typer.Context,
coords: List[str] = typer.Option(
None, '--coords', '-c',
help='Alt/Az coordinates to use, e.g. 40,120'
),
exptime: float = typer.Option(30.0, '--exptime', '-e', help='Exposure time in seconds.'),
num_exposures: int = typer.Option(
5, '--num-exposures', '-n',
help='Number of exposures per coordinate.'
),
field_name: str = typer.Option('PolarAlignment', '--field-name', '-f', help='Name of field.'),
) -> None:
"""Runs POCS in alignment mode.
Not specifying coordinates is the same as the following:
Expand Down

0 comments on commit 4f8bed7

Please sign in to comment.