Skip to content

main

Main FastAPI app for serving downloads.

run_in_process(fn, *args, **kwargs) async #

Helper to run in background

Source code in src/sdss_explorer/server/main.py
57
58
59
60
61
62
async def run_in_process(fn, *args, **kwargs):
    """Helper to run in background"""
    loop = asyncio.get_event_loop()
    return await loop.run_in_executor(app.state.executor,
                                      partial(fn, *args, **kwargs)
                                      )  # wait and return result

start_filter(uid, release, datatype, dataset, **kwargs) async #

Starts a filtering job

Source code in src/sdss_explorer/server/main.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
async def start_filter(uid: UUID, release: str, datatype: str, dataset: str,
                       **kwargs) -> None:
    """Starts a filtering job"""
    try:
        start = timer()
        jobs[uid].filepath = await run_in_process(filter_dataframe, uid,
                                                  release, datatype, dataset,
                                                  **kwargs)
        logger.info(f"job {uid} completed! took {timer() - start:.4f}s")
        jobs[uid].status = "complete"
    except Exception as e:
        logger.info(f"job {uid} failed: {e}")
        jobs[uid].message = str(e)
        jobs[uid].status = "failed"

status_all() async #

Get all job statuses

Source code in src/sdss_explorer/server/main.py
142
143
144
145
@app.get("/status-all")
async def status_all():
    """Get all job statuses"""
    return jobs

status_handler(uid) async #

Status check endpoint

Source code in src/sdss_explorer/server/main.py
136
137
138
139
@app.get("/status/{uid}")
async def status_handler(uid: UUID):
    """Status check endpoint"""
    return jobs[uid]

task_handler(background_tasks, release, datatype, dataset, name='A', expression='', carton='', mapper='', flags='', crossmatch='', cmtype='gaia_dr3', combotype='AND', invert=False) async #

Task handler endpoint

Note

You can't have this kwargs overload because it needs to know the properties.

Parameters:

Name Type Description Default
release str

data release to hit

required
datatype str

datatype, star or visit

required
dataset str

specific dataset

required
name str

name of subset, used in export

'A'
expression str

custom filter expression

''
carton str

list of cartons

''
mapper str

list of selected mappers

''
flags str

list of flags

''
crossmatch str

crossmatch multiline string

''
cmtype str

crossmatch identifier type to search for

'gaia_dr3'
combotype str

how to combine filters. unused.

'AND'
invert bool

whether to invert filters. unused.

False
Source code in src/sdss_explorer/server/main.py
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@app.post("/filter_subset/{release}/{datatype}/{dataset}",
          status_code=HTTPStatus.ACCEPTED)
async def task_handler(
    background_tasks: BackgroundTasks,
    release: str,
    datatype: str,
    dataset: str,
    name: str = "A",
    expression: str = "",
    carton: str = "",
    mapper: str = "",
    flags: str = "",
    crossmatch: str = "",
    cmtype: str = "gaia_dr3",
    combotype: str = "AND",
    invert: bool = False,
):
    """Task handler endpoint

    Note:
        You can't have this kwargs overload because it needs to know the properties.

    Args:
        release: data release to hit
        datatype: datatype, star or visit
        dataset: specific dataset
        name: name of subset, used in export
        expression: custom filter expression
        carton: list of cartons
        mapper: list of selected mappers
        flags: list of flags
        crossmatch: crossmatch multiline string
        cmtype: crossmatch identifier type to search for
        combotype: how to combine filters. unused.
        invert: whether to invert filters. unused.
    """
    new_task = Job()  # create jobspec
    jobs[new_task.uid] = new_task  # add to global joblist
    # bundle data
    kwargs = dict(
        name=name,
        expression=expression,
        carton=carton,
        mapper=mapper,
        flags=flags,
        crossmatch=crossmatch,
        cmtype=cmtype,
        combotype=combotype,
        invert=invert,
    )
    background_tasks.add_task(start_filter, new_task.uid, release, datatype,
                              dataset, **kwargs)
    return new_task