# Path: webphamerator/app/filters.py
# def replaceifequal(arg, value, replace_with):
# def humandate(timestamp):
# def isodate(date):
# def toclocktime(timedelta):
# 
# Path: webphamerator/app/celery_ext/tasks.py
# DB_SUCCESS = "Completed SQL database transcation."
# DB_FAILURE = "An unexpected error occurred during SQL database transaction."
# def create_database(job_id):
# def modify_database(job_id):
# def database_success(job_id):
# def database_failure(job_id):
# def database_task(job_id, task):
# def clean_job(job_record):
# def get_alchemist():
# def get_job(job_id):
# def get_database(database_id):
#     def __init__(self, job_id):
#     def handle_call(self, code, *args, **kwargs):
# class CallbackObserver(object):
# 
# Path: webphamerator/app/sqlalchemy_ext/models.py
# class Database(db.Model):
# class Job(db.Model):
# class JobOrganismToDelete(db.Model):
# class GenbankFile(db.Model):
# class Password(db.Model):
#     def url(self):
#     def mysql_name_for(cls, name):
#     def phamerator_name_for(cls, name):
#     def mysql_name(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):


import tempfile
import shutil
import os
import pham.genbank
import pham.db
import flask
from pathlib import Path
from flask import (abort, Blueprint, current_app, request)
from pdm_utils import AlchemyHandler
from webphamerator.app import sqlalchemy_ext as sqlext
from webphamerator.app import filters
from webphamerator.app.celery_ext import tasks
from webphamerator.app.sqlalchemy_ext import models


@bp.route('/api/jobs/<int:job_id>', methods=['GET'])
def job_status(job_id):
    job = sqlext.db.session.query(models.Job).filter(
                                            models.Job.id == job_id).first()
    if job is None:
        abort(404)

    elapsed_ms = None
    if job.runtime is not None:
        elapsed_ms = job.runtime.total_seconds() * 1000

    start_time = job.start_time
    if start_time is None:
        start_time = job.modified

    database_url = None
    if job.status_code == 'success':
        database_record = (sqlext.db.session.query(models.Database)
                           .filter(models.Database.id == job.database_id)
                           .first()
                           )
        if database_record is not None:
            database_url = database_record.url()

    return flask.jsonify(
                         statusCode=job.status_code,
                         statusMessage=job.status_message,
                         startTime=filters.isodate(start_time),

# Path: webphamerator/app/filters.py
# def replaceifequal(arg, value, replace_with):
# def humandate(timestamp):
# def isodate(date):
# def toclocktime(timedelta):
# 
# Path: webphamerator/app/celery_ext/tasks.py
# DB_SUCCESS = "Completed SQL database transcation."
# DB_FAILURE = "An unexpected error occurred during SQL database transaction."
# def create_database(job_id):
# def modify_database(job_id):
# def database_success(job_id):
# def database_failure(job_id):
# def database_task(job_id, task):
# def clean_job(job_record):
# def get_alchemist():
# def get_job(job_id):
# def get_database(database_id):
#     def __init__(self, job_id):
#     def handle_call(self, code, *args, **kwargs):
# class CallbackObserver(object):
# 
# Path: webphamerator/app/sqlalchemy_ext/models.py
# class Database(db.Model):
# class Job(db.Model):
# class JobOrganismToDelete(db.Model):
# class GenbankFile(db.Model):
# class Password(db.Model):
#     def url(self):
#     def mysql_name_for(cls, name):
#     def phamerator_name_for(cls, name):
#     def mysql_name(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):


# Path: webphamerator/app/api.py
import tempfile
import shutil
import os
import pham.genbank
import pham.db
import flask
from pathlib import Path
from flask import (abort, Blueprint, current_app, request)
from pdm_utils import AlchemyHandler
from webphamerator.app import sqlalchemy_ext as sqlext
from webphamerator.app import filters
from webphamerator.app.celery_ext import tasks
from webphamerator.app.sqlalchemy_ext import models



@bp.route('/api/jobs/<int:job_id>', methods=['GET'])
def job_status(job_id):
    job = sqlext.db.session.query(models.Job).filter(
                                            models.Job.id == job_id).first()
    if job is None:
        abort(404)

    elapsed_ms = None
    if job.runtime is not None:
        elapsed_ms = job.runtime.total_seconds() * 1000

    start_time = job.start_time
    if start_time is None:
        start_time = job.modified

    database_url = None
    if job.status_code == 'success':
        database_record = (sqlext.db.session.query(models.Database)
                           .filter(models.Database.id == job.database_id)
                           .first()
                           )
        if database_record is not None:
            database_url = database_record.url()

    return flask.jsonify(
                         statusCode=job.status_code,
                         statusMessage=job.status_message,
                         startTime=filters.isodate(start_time),

                         endTime=filters.isodate(job.modified),