File size: 891 Bytes
aac350d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Export service — export job results as downloadable JSON."""

from __future__ import annotations

import json
from typing import Optional

from storage.database import Database


class ExportService:
    """Exports job results."""

    def __init__(self, database: Database) -> None:
        self._db = database

    def export_job_json(self, job_id: str) -> Optional[dict]:
        """Returns a dict combining job metadata + result.  None if not found."""
        job = self._db.get_job(job_id)
        if not job:
            return None
        result = self._db.get_result(job_id) or {}
        return {
            "job": job,
            "result": result,
        }

    def export_job_json_str(self, job_id: str) -> Optional[str]:
        data = self.export_job_json(job_id)
        if data is None:
            return None
        return json.dumps(data, indent=2, default=str)