Commit dd7f2965 authored by Vermaat's avatar Vermaat
Browse files

Merge pull request #111 from mutalyzer/batch-download-url

Fix link in batch notification if submitted from webservice
parents ceac492d 3f57c5c9
......@@ -184,6 +184,14 @@ REVERSE_PROXIED
`Default value:` `False`
.. _config-website-root-url:
WEBSITE_ROOT_URL
URL to the website root (without trailing slash). Used for generating
download links in the batch scheduler.
`Default value:` `None`
.. _config-soap-wsdl-url:
SOAP_WSDL_URL
......
......@@ -30,6 +30,7 @@ settings:
- :ref:`EMAIL <config-email>`
- :ref:`DEBUG <config-debug>`
- :ref:`CACHE_DIR <config-cache-dir>`
- :ref:`WEBSITE_ROOT_URL <config-website-root-url>`
- :ref:`SOAP_WSDL_URL <config-soap-wsdl-url>`
- :ref:`JSON_ROOT_URL <config-json-root-url>`
- :ref:`REVERSE_PROXIED <config-reverse-proxied>`
......
......@@ -33,6 +33,7 @@ from mutalyzer.grammar import Grammar
from mutalyzer.output import Output
from mutalyzer.mapping import Converter
from mutalyzer import Retriever # Retriever.Retriever
from mutalyzer import website
__all__ = ["Scheduler"]
......@@ -83,7 +84,7 @@ class Scheduler() :
return not self.__run
#stopped
def __sendMail(self, mailTo, url) :
def __sendMail(self, mailTo, result_id):
"""
Send an e-mail containing an url to a batch job submitter.
......@@ -91,8 +92,8 @@ class Scheduler() :
@arg mailTo: The batch job submitter
@type mailTo: unicode
@arg url: The url containing the results
@type url: unicode
@arg result_id: Identifier for the job result.
@type result_id: unicode
"""
if settings.TESTING:
return
......@@ -105,6 +106,9 @@ class Scheduler() :
#TODO: Handle Connection errors in a try, except clause
#Expected errors: socket.error
download_url = website.url_for('batch_job_result',
result_id=result_id)
message = MIMEText("""Dear submitter,
The batch operation you have submitted, has been processed successfully.
......@@ -116,7 +120,7 @@ Thanks for using Mutalyzer.
With kind regards,
Mutalyzer batch scheduler""" % url)
Mutalyzer batch scheduler""" % download_url)
message["Subject"] = "Result of your Mutalyzer batch job"
message["From"] = settings.EMAIL
......@@ -367,10 +371,6 @@ Mutalyzer batch scheduler""" % url)
# Group batch jobs by email address and retrieve the oldest for
# each address. This improves fairness when certain users have
# many jobs.
# Note that batch jobs submitted via the webservices all have the
# same email address, so they are effectively throttled as if all
# from the same user. Adapting the webservices to also allow
# setting an email address is future work.
batch_jobs = BatchJob.query.filter(BatchJob.id.in_(
session.query(func.min(BatchJob.id)).group_by(BatchJob.email))
).all()
......@@ -403,7 +403,7 @@ Mutalyzer batch scheduler""" % url)
else:
print ('Job %s finished, email %s file %s'
% (batch_job.id, batch_job.email, batch_job.id))
self.__sendMail(batch_job.email, batch_job.download_url)
self.__sendMail(batch_job.email, batch_job.result_id)
session.delete(batch_job)
session.commit()
#process
......@@ -729,8 +729,7 @@ Mutalyzer batch scheduler""" % url)
"Finished SNP converter batch rs%s" % cmd)
#_processSNP
def addJob(self, email, queue, columns, job_type, argument=None,
create_download_url=None):
def addJob(self, email, queue, columns, job_type, argument=None):
"""
Add a job to the Database and start the BatchChecker.
......@@ -744,18 +743,12 @@ Mutalyzer batch scheduler""" % url)
@type job_type:
@arg argument: Batch Arguments, for now only build info
@type argument:
@arg create_download_url: Function accepting a result_id and returning
the URL for downloading the batch job
result. Can be None.
@type create_download_url: function
@return: result_id
@rtype:
"""
# Add jobs to the database
batch_job = BatchJob(job_type, email=email, argument=argument)
if create_download_url:
batch_job.download_url = create_download_url(batch_job.result_id)
session.add(batch_job)
for i, inputl in enumerate(queue):
......
......@@ -28,7 +28,7 @@ __date__ = '1 Oct 2015'
__version__ = '.'.join(__version_info__)
__author__ = 'Leiden University Medical Center'
__contact__ = 'humgen@lumc.nl'
__homepage__ = 'http://mutalyzer.nl'
__homepage__ = 'https://mutalyzer.nl'
NOMENCLATURE_VERSION_INFO = ('2', '0')
......
......@@ -69,6 +69,10 @@ BATCH_JOBS_ERROR_THRESHOLD = 0.05
# (in seconds).
NEGATIVE_LINK_CACHE_EXPIRATION = 60 * 60 * 24 * 30
# URL to the website root (without trailing slash). Used for generating
# download links in the batch scheduler.
WEBSITE_ROOT_URL = None
# URL to the SOAP webservice WSDL document. Used to build the WSDL document
# and for linking to it from the documentation page on the website.
SOAP_WSDL_URL = None
......
......@@ -77,7 +77,7 @@ class MutalyzerService(ServiceBase):
Submit a batch job.
Input and output file formats for batch jobs are explained on the
website <https://mutalyzer.nl/batch>.
website <https://mutalyzer.nl/batch-jobs>.
Batch jobs are processed using round-robin scheduling grouped by email
address (or client IP address if no email address is specified). Per
......@@ -167,7 +167,7 @@ class MutalyzerService(ServiceBase):
Get the number of entries left for a batch job.
Input and output file formats for batch jobs are explained on the
website <https://mutalyzer.nl/batch>.
website <https://mutalyzer.nl/batch-jobs>.
@arg job_id: Batch job identifier.
......@@ -181,7 +181,7 @@ class MutalyzerService(ServiceBase):
Get the result of a batch job.
Input and output file formats for batch jobs are explained on the
website <https://mutalyzer.nl/batch>.
website <https://mutalyzer.nl/batch-jobs>.
On error an exception is raised:
- detail: Human readable description of the error.
......
......@@ -156,8 +156,8 @@ class CacheSync(object):
::
>>> wsdl = 'http://mutalyzer.nl/mutalyzer/services/?wsdl'
>>> template = 'http://mutalyzer.nl/mutalyzer/Reference/{file}'
>>> wsdl = 'https://mutalyzer.nl/mutalyzer/services/?wsdl'
>>> template = 'https://mutalyzer.nl/mutalyzer/Reference/{file}'
>>> self.sync_with_remote(wsdl, template)
(14, 3)
......
......@@ -8,6 +8,7 @@ from __future__ import unicode_literals
import logging
import os
import pkg_resources
import urlparse
from flask import Flask
......@@ -46,3 +47,22 @@ def create_app():
session.remove()
return app
def url_for(endpoint, **values):
"""
Generates a URL to the given website endpoint.
Like :func:`Flask.url_for`, but for when you don't have an application or
request context.
Note that the generated URL will be based on the `WEBSITE_ROOT_URL`
configuration setting or `http://localhost` if not set.
:arg str endpoint: The endpoint of the URL (name of the function).
:arg str values: The variable arguments of the URL rule.
"""
root = urlparse.urlsplit(settings.WEBSITE_ROOT_URL or 'http://localhost')
url_map = create_app().url_map.bind(root.netloc, root.path or '/',
url_scheme=root.scheme)
return url_map.build('website.%s' % endpoint, values, force_external=True)
/*
* Mutalyzer Name Generator v0.1
* http://www.mutalyzer.nl/
* https://www.mutalyzer.nl/
* © 2010 LUMC
*/
......
......@@ -937,15 +937,8 @@ def batch_jobs_submit():
errors.append('Could not parse input file, please check your '
'file format.')
else:
# Creates the result download URL from a job result_id.
def create_download_url(result_id):
return url_for('.batch_job_result',
result_id=result_id,
_external=True)
result_id = scheduler.addJob(
email, job, columns, job_type, argument=argument,
create_download_url=create_download_url)
result_id = scheduler.addJob(email, job, columns, job_type,
argument=argument)
# Todo: We now assume that the job was not scheduled if there are
# messages, which is probably not correct.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment