def prepare_job(params): """ Create a new OqJob and fill in the related OpParams entry. Returns the newly created job object. """ # TODO specify the owner as a command line parameter owner = OqUser.objects.get(user_name='openquake') input_set = InputSet(upload=None, owner=owner) input_set.save() job_type = CALCULATION_MODE[params['CALCULATION_MODE']] job = OqJob(owner=owner, path=None, job_type=job_type) oqp = OqParams(input_set=input_set) oqp.job_type = job_type _insert_input_files(params, input_set) _store_input_parameters(params, job_type, oqp) oqp.save() job.oq_params = oqp job.save() # Reset all progress indication counters for the job at hand. stats.delete_job_counters(job.id) return job
def _prepare_job(params, sections, owner_username='******'): """ Create a new OqCalculation and fill in the related OqJobProfile entry. Returns the newly created job object. :param dict params: The job config params. :params sections: The job config file sections, as a list of strings. :returns: A new :class:`openquake.db.models.OqJobProfile` object. """ @transaction.commit_on_success(using='job_init') def _get_job_profile(input_set, calc_mode, job_type, owner): """Create an OqJobProfile, save it to the db, commit, and return.""" job_profile = OqJobProfile(input_set=input_set, calc_mode=calc_mode, job_type=job_type) _insert_input_files(params, input_set) _store_input_parameters(params, calc_mode, job_profile) job_profile.owner = owner job_profile.save() return job_profile # TODO specify the owner as a command line parameter owner = OqUser.objects.get(user_name=owner_username) input_set = InputSet(upload=None, owner=owner) input_set.save() calc_mode = CALCULATION_MODE[params['CALCULATION_MODE']] job_type = [s.lower() for s in sections if s.upper() in [jobconf.HAZARD_SECTION, jobconf.RISK_SECTION]] job_profile = _get_job_profile(input_set, calc_mode, job_type, owner) job_profile.owner = owner # When querying this record from the db, Django changes the values # slightly (with respect to geometry, for example). Thus, we want a # "fresh" copy of the record from the db. return OqJobProfile.objects.get(id=job_profile.id)