def _create_supervisor_state_file(run_dir): try: i, t = _load_in_json(run_dir) except Exception as e: if pykern.pkio.exception_is_not_found(e): return raise u = simulation_db.uid_from_dir_name(run_dir) sirepo.auth.cfg.logged_in_user = u c = sim_data.get_class(i.simulationType) d = PKDict( computeJid=c.parse_jid(i, u), computeJobHash=c.compute_job_hash( i), # TODO(e-carlin): Another user cookie problem computeJobSerial=t, computeJobStart=t, error=None, history=[], isParallel=c.is_parallel(i), simulationId=i.simulationId, simulationType=i.simulationType, uid=u, ) d.pkupdate( jobRunMode=job.PARALLEL if d.isParallel else job.SEQUENTIAL, nextRequestSeconds=c.poll_seconds(i), ) _add_compute_status(run_dir, d) if d.status not in (job.COMPLETED, job.CANCELED): return if d.isParallel: _add_parallel_status(i, c, run_dir, d) util.json_dump(d, path=_db_file(d.computeJid))
def write_json(filename, data): """Write data as json to filename pretty is true. Args: filename (py.path or str): will append JSON_SUFFIX if necessary """ util.json_dump(data, path=json_filename(filename), pretty=True)
def generate_json(data, pretty=False): """Convert data to JSON to be send back to client Use only for responses. Use `:func:write_json` to save. Args: data (dict): what to format pretty (bool): pretty print [False] Returns: str: formatted data """ return util.json_dump(data, pretty=pretty)