def run_job(credential, gjfstring, jobstring=None, **kwargs): results = { "jobid": None, "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results with ssh, sftp: jobid, error = _run_job(ssh, sftp, gjfstring, jobstring, **kwargs) results["jobid"] = jobid results["error"] = error if not error: job = Job(credential=credential, jobid=jobid, **kwargs) job.save() return results
def run_job(credential, gjfstring, jobstring=None, **kwargs): results = { "jobid": None, "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results with ssh, sftp: jobid, error = _run_job(ssh, sftp, gjfstring, jobstring, **kwargs) results["jobid"] = jobid results["error"] = error if not error: job = Job( credential=credential, jobid=jobid, **kwargs ) job.save() return results
def run_jobs(credential, names, gjfstrings, jobstring=None, **kwargs): results = { "worked": [], "failed": [], "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results jobs = [] with ssh, sftp: for name, gjf in zip(names, gjfstrings): dnew = kwargs.copy() dnew["name"] = re.sub( r"{{\s*name\s*}}", name, dnew.get("name", "{{ name }}")) jobid, error = _run_job(ssh, sftp, gjf, jobstring, **dnew) if error is None: results["worked"].append((name, jobid)) job = Job( credential=credential, molecule=name, jobid=jobid, **dnew ) jobs.append(job) else: results["failed"].append((name, error)) Job.objects.bulk_create(jobs) return results
def run_jobs(credential, names, gjfstrings, jobstring=None, **kwargs): results = { "worked": [], "failed": [], "error": None, } try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results ssh = get_ssh_connection_obj(credential) sftp = get_sftp_connection_obj(credential) except: results["error"] = "Invalid credential" results["cluster"] = None logger.info("Invalid credential %s" % credential) return results jobs = [] with ssh, sftp: for name, gjf in zip(names, gjfstrings): dnew = kwargs.copy() dnew["name"] = re.sub(r"{{\s*name\s*}}", name, dnew.get("name", "{{ name }}")) jobid, error = _run_job(ssh, sftp, gjf, jobstring, **dnew) if error is None: results["worked"].append((name, jobid)) job = Job(credential=credential, molecule=name, jobid=jobid, **dnew) jobs.append(job) else: results["failed"].append((name, error)) Job.objects.bulk_create(jobs) return results