Commit 5867693b authored by Vermaat's avatar Vermaat
Browse files

Fix link in batch notification if submitted from webservice

parent 09c2755a
......@@ -184,6 +184,14 @@ REVERSE_PROXIED
`Default value:` `False`
.. _config-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:
......@@ -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
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:
......@@ -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',
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
......@@ -403,7 +407,7 @@ Mutalyzer batch scheduler""" % url)
print ('Job %s finished, email %s file %s'
% (,,
self.__sendMail(, batch_job.download_url)
self.__sendMail(, batch_job.result_id)
......@@ -729,8 +733,7 @@ Mutalyzer batch scheduler""" % url)
"Finished SNP converter batch rs%s" % cmd)
def addJob(self, email, queue, columns, job_type, argument=None,
def addJob(self, email, queue, columns, job_type, argument=None):
Add a job to the Database and start the BatchChecker.
......@@ -744,18 +747,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
# 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)
for i, inputl in enumerate(queue):
......@@ -69,6 +69,10 @@ BATCH_JOBS_ERROR_THRESHOLD = 0.05
# (in seconds).
# URL to the website root (without trailing slash). Used for generating
# download links in the batch scheduler.
# 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.
......@@ -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():
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 '/',
return'website.%s' % endpoint, values, force_external=True)
......@@ -937,15 +937,8 @@ def batch_jobs_submit():
errors.append('Could not parse input file, please check your '
'file format.')
# Creates the result download URL from a job result_id.
def create_download_url(result_id):
return url_for('.batch_job_result',
result_id = scheduler.addJob(
email, job, columns, job_type, argument=argument,
result_id = scheduler.addJob(email, job, columns, job_type,
# 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