Beispiel #1
0
 def __init__(self, data):
     with self._lock:
         self.jid = simulation_db.job_id(data)
         pkdc('{}: created', self.jid)
         if self.jid in self._job:
             pkdlog(
                 '{}: Collision tid={} celery_state={}',
                 jid,
                 self.async_result,
                 self.async_result and self.async_result.state,
             )
             raise Collision(self.jid)
         self.cmd, self.run_dir = simulation_db.prepare_simulation(data)
         self._job[self.jid] = self
         self.data = data
         self._job[self.jid] = self
         self.async_result = self._start_job()
         pkdc(
             '{}: started tid={} dir={} queue={} len_jobs={}',
             self.jid,
             self.async_result.task_id,
             self.run_dir,
             self.celery_queue,
             len(self._job),
         )
Beispiel #2
0
 def __init__(self, data):
     with self._lock:
         self.jid = simulation_db.job_id(data)
         pkdc('{}: created', self.jid)
         if self.jid in self._job:
             self = self._job[self.jid]
             pkdlog(
                 '{}: Collision tid={} celery_state={}',
                 self.jid,
                 self.async_result,
                 self.async_result and self.async_result.state,
             )
             raise Collision(self.jid)
         self.cmd, self.run_dir = simulation_db.prepare_simulation(data)
         self._job[self.jid] = self
         self.data = data
         self._job[self.jid] = self
         self.async_result = self._start_job()
         pkdc(
             '{}: started tid={} dir={} queue={} len_jobs={}',
             self.jid,
             self.async_result.task_id,
             self.run_dir,
             self.celery_queue,
             len(self._job),
         )
Beispiel #3
0
def _do_prepare_simulation(msg, template):
    if 'libFileList' in msg:
        msg.data.libFileList = msg.libFileList
    return PKDict(cmd=simulation_db.prepare_simulation(
        msg.data,
        msg.runDir,
    )[0], )
Beispiel #4
0
 def __init__(self, data):
     with self._lock:
         self.jid = simulation_db.job_id(data)
         if self.jid in self._job:
             raise Collision(self.jid)
         self.in_kill = None
         self.cmd, self.run_dir = simulation_db.prepare_simulation(data)
         self._job[self.jid] = self
         self.pid = None
         # This command may blow up
         self.pid = self._start_job()
Beispiel #5
0
 def __init__(self, data):
     with self._lock:
         self.jid = simulation_db.job_id(data)
         if self.jid in self._job:
             raise Collision(self.jid)
         self.in_kill = None
         self.cmd, self.run_dir = simulation_db.prepare_simulation(data)
         self._job[self.jid] = self
         self.pid = None
         # This command may blow up
         self.pid = self._start_job()
Beispiel #6
0
 def start(self):
     with self.lock:
         if self.state == State.STOP:
             # Something killed between INIT and START so don't start
             return
         elif self.state in (State.KILL, State.RUN):
             # normal case (RUN) or race condition on start/kill
             # with a thread that died while trying to kill this
             # job before it was started.  Have to finish the KILL.
             self.kill()
             return
         else:
             # race condition that doesn't seem possible
             assert self.state == State.INIT, \
                 '{}: unexpected state for jid={}'.format(self.state, self.jid)
         self.set_state(State.START)
         self.cmd, self.run_dir = simulation_db.prepare_simulation(self.data)
         self._start()
         self.set_state(State.RUN)
Beispiel #7
0
def api_runSimulation():
    from pykern import pkjson
    data = _parse_data_input(validate=True)
    # if flag is set
    # - check status
    # - if status is bad, rewrite the run dir (XX race condition, to fix later)
    # - then request it be started
    if feature_config.cfg.runner_daemon:
        jhash = template_common.report_parameters_hash(data)
        run_dir = simulation_db.simulation_run_dir(data)
        status = runner_client.report_job_status(run_dir, jhash)
        already_good_status = [
            runner_client.JobStatus.RUNNING, runner_client.JobStatus.COMPLETED
        ]
        if status not in already_good_status:
            data['simulationStatus'] = {
                'startTime': int(time.time()),
                'state': 'pending',
            }
            tmp_dir = run_dir + '-' + jhash + '-' + uuid.uuid4(
            ) + srdb.TMP_DIR_SUFFIX
            cmd, _ = simulation_db.prepare_simulation(data, tmp_dir=tmp_dir)
            runner_client.start_report_job(run_dir, jhash, cfg.backend, cmd,
                                           tmp_dir)
        res = _simulation_run_status_runner_daemon(data, quiet=True)
        return http_reply.gen_json(res)
    else:
        res = _simulation_run_status(data, quiet=True)
        if ((not res['state'] in _RUN_STATES and
             (res['state'] != 'completed' or data.get('forceRun', False)))
                or res.get('parametersChanged', True)):
            try:
                _start_simulation(data)
            except runner.Collision:
                pkdlog('{}: runner.Collision, ignoring start',
                       simulation_db.job_id(data))
            res = _simulation_run_status(data)
        return http_reply.gen_json(res)