Ejemplo n.º 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),
         )
Ejemplo n.º 2
0
def api_runCancel():
    data = _parse_data_input()
    jid = simulation_db.job_id(data)
    if feature_config.cfg.runner_daemon:
        jhash = template_common.report_parameters_hash(data)
        run_dir = simulation_db.simulation_run_dir(data)
        runner_client.cancel_report_job(run_dir, jhash)
        # Always true from the client's perspective
        return http_reply.gen_json({'state': 'canceled'})
    else:
        # TODO(robnagler) need to have a way of listing jobs
        # Don't bother with cache_hit check. We don't have any way of canceling
        # if the parameters don't match so for now, always kill.
        #TODO(robnagler) mutex required
        if runner.job_is_processing(jid):
            run_dir = simulation_db.simulation_run_dir(data)
            # Write first, since results are write once, and we want to
            # indicate the cancel instead of the termination error that
            # will happen as a result of the kill.
            simulation_db.write_result({'state': 'canceled'}, run_dir=run_dir)
            runner.job_kill(jid)
            # TODO(robnagler) should really be inside the template (t.cancel_simulation()?)
            # the last frame file may not be finished, remove it
            t = sirepo.template.import_module(data)
            if hasattr(t, 'remove_last_frame'):
                t.remove_last_frame(run_dir)
        # Always true from the client's perspective
        return http_reply.gen_json({'state': 'canceled'})
Ejemplo n.º 3
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),
         )
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 6
0
def job_start(data):
    with _job_map_lock:
        jid = simulation_db.job_id(data)
        if jid in _job_map:
#TODO(robnagler) assumes external check of is_processing,
# which server._simulation_run_status does do, but this
# could be cleaner. Really want a reliable daemon thread
# to manage all this.
            raise Collision(jid)
        job = _job_class(jid, data)
        _job_map[jid] = job
    job.start()
Ejemplo n.º 7
0
def api_runSimulation():
    data = _parse_data_input(validate=True)
    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 _json_response(res)
Ejemplo n.º 8
0
def app_run_simulation():
    data = _parse_data_input(validate=True)
    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 _json_response(res)
Ejemplo n.º 9
0
def app_run_cancel():
    data = _parse_data_input()
    jid = simulation_db.job_id(data)
    # TODO(robnagler) need to have a way of listing jobs
    # Don't bother with cache_hit check. We don't have any way of canceling
    # if the parameters don't match so for now, always kill.
    #TODO(robnagler) mutex required
    if cfg.job_queue.is_processing(jid):
        run_dir = simulation_db.simulation_run_dir(data)
        # Write first, since results are write once, and we want to
        # indicate the cancel instead of the termination error that
        # will happen as a result of the kill.
        simulation_db.write_result({'state': 'canceled'}, run_dir=run_dir)
        cfg.job_queue.kill(jid)
        # TODO(robnagler) should really be inside the template (t.cancel_simulation()?)
        # the last frame file may not be finished, remove it
        t = sirepo.template.import_module(data)
        t.remove_last_frame(run_dir)
    # Always true from the client's perspective
    return _json_response({'state': 'canceled'})
Ejemplo n.º 10
0
def api_runCancel():
    data = _parse_data_input()
    jid = simulation_db.job_id(data)
    # TODO(robnagler) need to have a way of listing jobs
    # Don't bother with cache_hit check. We don't have any way of canceling
    # if the parameters don't match so for now, always kill.
    #TODO(robnagler) mutex required
    if cfg.job_queue.is_processing(jid):
        run_dir = simulation_db.simulation_run_dir(data)
        # Write first, since results are write once, and we want to
        # indicate the cancel instead of the termination error that
        # will happen as a result of the kill.
        simulation_db.write_result({'state': 'canceled'}, run_dir=run_dir)
        cfg.job_queue.kill(jid)
        # TODO(robnagler) should really be inside the template (t.cancel_simulation()?)
        # the last frame file may not be finished, remove it
        t = sirepo.template.import_module(data)
        t.remove_last_frame(run_dir)
    # Always true from the client's perspective
    return _json_response({'state': 'canceled'})
Ejemplo n.º 11
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)