Skip to content
Snippets Groups Projects
Commit 63243903 authored by Vermaat's avatar Vermaat
Browse files

List batch jobs in admin interface

parent 217abd4a
No related branches found
No related tags found
No related merge requests found
...@@ -14,13 +14,14 @@ import os ...@@ -14,13 +14,14 @@ import os
import alembic.command import alembic.command
import alembic.config import alembic.config
from alembic.migration import MigrationContext from alembic.migration import MigrationContext
import sqlalchemy
from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.exc import NoResultFound
from . import _cli_string from . import _cli_string
from .. import announce from .. import announce
from .. import db from .. import db
from ..db import session from ..db import session
from ..db.models import Assembly, Chromosome from ..db.models import Assembly, BatchJob, BatchQueueItem, Chromosome
from .. import mapping from .. import mapping
from .. import output from .. import output
from .. import sync from .. import sync
...@@ -151,6 +152,50 @@ def sync_cache(wsdl_url, url_template, history=7): ...@@ -151,6 +152,50 @@ def sync_cache(wsdl_url, url_template, history=7):
% (inserted, downloaded)) % (inserted, downloaded))
def list_batch_jobs():
"""
List batch jobs.
"""
# For getting all batch jobs and their item counts, the following query
# might be more obvious at first thought. However, our current query below
# turns out to be more than twice as fast (and shorter).
#
# sq = session.query(
# BatchQueueItem.batch_job_id,
# sqlalchemy.func.count(BatchQueueItem.id).label('count')
# ).group_by(BatchQueueItem.batch_job_id).subquery()
# session.query(
# BatchJob,
# sq.c.count
# ).join(sq, BatchJob.id == sq.c.batch_job_id)
#
batch_jobs_with_counts = session.query(
BatchJob,
session.query(sqlalchemy.func.count('*')).filter(
BatchQueueItem.batch_job_id == BatchJob.id
).label('count')
).order_by(BatchJob.added.asc()).all()
lengths = {
'id_len': max(len(str(j.id)) for j, _ in batch_jobs_with_counts),
'type_len': max(len(j.job_type) for j, _ in batch_jobs_with_counts),
'count_len': max(len(str(c)) for _, c in batch_jobs_with_counts),
'email_len': max(len(j.email) for j, _ in batch_jobs_with_counts)
}
template = ('{id:{id_len}} {type:<{type_len}} {added:%Y-%m-%d %H:%M:%S}'
' {count:<{count_len}} {email:{email_len}}')
for batch_job, count in batch_jobs_with_counts:
print template.format(
id=batch_job.id,
type=batch_job.job_type,
added=batch_job.added,
count=count,
email=batch_job.email,
**lengths)
def set_announcement(body, url=None): def set_announcement(body, url=None):
""" """
Set announcement to show to the user. Set announcement to show to the user.
...@@ -309,6 +354,12 @@ def main(): ...@@ -309,6 +354,12 @@ def main():
description=unset_announcement.__doc__.split('\n\n')[0]) description=unset_announcement.__doc__.split('\n\n')[0])
p.set_defaults(func=unset_announcement) p.set_defaults(func=unset_announcement)
# Subparser 'batch-jobs'.
p = subparsers.add_parser(
'batch-jobs', help='list batch jobs',
description=list_batch_jobs.__doc__.split('\n\n')[0])
p.set_defaults(func=list_batch_jobs)
# Subparser 'sync-cache'. # Subparser 'sync-cache'.
p = subparsers.add_parser( p = subparsers.add_parser(
'sync-cache', help='synchronize cache with remote Mutalyzer', 'sync-cache', help='synchronize cache with remote Mutalyzer',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment