def make_email_subject(job_id): """ Creates a subject line specific to a job. Args: job_id (str): a unique identifier for a job Returns: str: the subject line containing the job ID, description, and job type Raises: Exception: raises any exception resulting from the database fetch and formatting """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() if tfvars.environment in ['dev', 'qa']: return "Nephele Job: {id} ({type} - {desc}) -- {env}"\ .format(env=tfvars.environment, id=job_id, type=job.job_type.name, desc=job.description) return "Nephele Job: {id} ({type} - {desc})"\ .format(id=job_id, type=job.job_type.name, desc=job.description) except sqlalchemy.orm.exc.NoResultFound: raise RuntimeError( 'Unable to find job, failed to make_email_subject', job_id)
def get_job_type_details(job_id): """ Gets details about the job type from the job ID. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a valid job ID Returns: dict: a dict containing the job name and data type:: { 'name': pipe_name, 'data_type': data_type, 'ami_id': ami_id, 'default_instance_type': default_instance_type } Raises: """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() job_details = {} job_details['name'] = job.job_type.name job_details['data_type'] = job.job_type.data_type job_details['ami_id'] = job.job_type.ami_id job_details['default_instance_type'] = \ job.job_type.default_instance_type return job_details except sqlalchemy.orm.exc.NoResultFound: return None
def get_user_and_email_by_email(email_addr): with nephele2.db_read() as db: try: user = db.query(User).filter_by(email_address=email_addr).one() user_email = user.user_address return (user, user_email) except sqlalchemy.orm.exc.NoResultFound: return (None, None)
def get_job(job_id): """ Gets a job by it's primary key. """ with nephele2.db_read() as db: try: return db.query(Job).filter_by(job_id=job_id).one() except sqlalchemy.orm.exc.NoResultFound: return None
def get_old_unsubmitted_jobs(): """Looks up jobs that were created > a day ago and have not been submitted. Args: db (SQLClient): a SQLAlchemy database read connection Returns: list(str): a list of old job IDs. """ yesterday = datetime.now() - timedelta(hours=24) with nephele2.db_read() as db: jobs = db.query(Job).filter(Job.status == "Initializing", Job.created < yesterday) return [j.job_id for j in jobs.all()]
def get_user_by_email(email_addr): """ Retrieves the user by email address. Args: db (SQLClient): a SQLAlchemy database read connection email_addr (str): a validly formatted email address Returns: :obj:`User`: a User object """ with nephele2.db_read() as db: try: return db.query(User).filter_by(email_address=email_addr).one() except sqlalchemy.orm.exc.NoResultFound: return None
def get_old_unconfirmed_users(): """Looks up users who registered > a day ago and have not confirmed. Args: db (SQLClient): a SQLAlchemy database read connection Returns: list(str): list of bad emails. Raises: Exception: any exception thrown """ yesterday = datetime.now() - timedelta(hours=24) with nephele2.db_read() as db: users = db.query(UserEmail).filter( UserEmail.is_confirmed.is_(False), UserEmail.subscr_date < yesterday) return [u.address for u in users.all()]
def get_job_type_by_name(name): """ Gets a JobType object by name. Args: db (SQLClient): a SQLAlchemy database read connection name (str): name of the job to run, from job_type.name Returns: :obj:`JobType`: a JobType object Raises: """ with nephele2.db_read() as db: try: return db.query(JobType).filter(JobType.name == name).one() except sqlalchemy.orm.exc.NoResultFound: return None
def get_user_by_job_id(job_id): """ Returns a User object associated with the job_id. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a valid job ID Returns: :obj:`User`: a User object """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.user except sqlalchemy.orm.exc.NoResultFound: return None
def get_job_status(job_id): """ Gets the status for the job with the requested ID. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a valid job ID Returns: str: the status of the requested job, one of ['Pending','Pre-Processing', 'Running','Failed','Succeeded'] """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.status except sqlalchemy.orm.exc.NoResultFound: return None
def get_machine_info(machine_id): """ Returns a MachineInfo object. Args: db (SQLClient): a SQLAlchemy database read connection machine_id (str): an AWS machine ID Returns: :obj:`MachineInfo`: a MachineInfo object Raises: """ with nephele2.db_read() as db: try: return db.query(MachineInfo).filter_by( instance_id=machine_id).one() except sqlalchemy.orm.exc.NoResultFound: return None
def get_machine_info_by_job_id(job_id): """ Returns the MachineInfo object associated with the specified job, if one exists. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a valid job ID (required) Returns: :obj:`MachinInfo`: a MachineInfo object Raises: """ with nephele2.db_read() as db: try: return db.query(MachineInfo).filter_by(job_id=job_id).one() except sqlalchemy.orm.exc.NoResultFound: return None
def get_job_description(job_id): """ Returns the job description, may be NULL. Args: job_id (str): a job id Returns: str: a string describing the job or NULL Raises: """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.description except sqlalchemy.orm.exc.NoResultFound: return None
def get_error_msg(job_id): """ Returns the error message for the job. Value may be NULL. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a unique identifier for a job Returns: str: the error message string for the job Raises: """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.error_msg except sqlalchemy.orm.exc.NoResultFound: return None
def get_job_id(instance_id): """ Retrieves the job ID mapped to the given machine_id. Args: instance_id (str): an AWS machine identifier Returns: str: a job id Raises: """ with nephele2.db_read() as db: try: machine = db.query(MachineInfo).filter_by( instance_id=instance_id).one() return machine.job_id except sqlalchemy.orm.exc.NoResultFound: return None
def get_job_arguments(job_id): """ Gets the arguments for the requested job. These are the arguments that will actually be used for running the job. Args: job_id (str): a unique identifier for a job Returns: str: the arguments for the job as a JSON string Raises: """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.args except sqlalchemy.orm.exc.NoResultFound: return None
def get_subscribed_user_email(): """ Gets a list of all confirmed email address, that aren't flagged as bad, that are subscribed to the newsletter. Args: db (SQLClient): a SQLAlchemy database read connection Returns: list(str): a list of email addresses Raises: """ with nephele2.db_read() as db: users = db.query(UserEmail).filter( UserEmail.subscribed.is_(True), UserEmail.is_confirmed.is_(True), UserEmail.is_bad.isnot(True)).all() addresses = [] for user in users: addresses.append(user.address) return addresses
def get_data_transferred(job_id): """ Gets the data transfer status for the job with the requested ID. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a valid job ID Returns: bool: transfer status of the requested job Raises: RuntimeError: if job can't be found """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.transferred except sqlalchemy.orm.exc.NoResultFound: raise RuntimeError( 'Cannot find job, unable to get transferred status', job_id)
def get_script_name(job_id): """ Gets the script location for the type of job associated with the job_id. Args: db (SQLClient): a SQLAlchemy database read connection job_id (str): a valid job ID Returns: str: script name Examples: >>> with nephele2.db_write() as db: a = get_script_name(db,"1") print(a) "QIIME/qiime.py" """ with nephele2.db_read() as db: try: job = db.query(Job).filter_by(job_id=job_id).one() return job.job_type.package + '/' + job.job_type.script_name except sqlalchemy.orm.exc.NoResultFound: return None