Milimetric has uploaded a new change for review.
https://gerrit.wikimedia.org/r/75883
Change subject: guids in report result URLs
......................................................................
guids in report result URLs
Change-Id: I734cb70b5da83a2b68016623734e4486f1c79cee
---
M wikimetrics/controllers/reports.py
M wikimetrics/static/css/site.css
M wikimetrics/templates/reports.html
3 files changed, 46 insertions(+), 54 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics
refs/changes/83/75883/1
diff --git a/wikimetrics/controllers/reports.py
b/wikimetrics/controllers/reports.py
index 0dff11d..664fcf1 100644
--- a/wikimetrics/controllers/reports.py
+++ b/wikimetrics/controllers/reports.py
@@ -71,7 +71,7 @@
jr = RunReport(metric_reports, name=name)
async_response = jr.task.delay()
app.logger.info(
- 'starting report with database id: %s, PersistentReport.id: %d',
+ 'starting report with celery id: %s, PersistentReport.id: %d',
async_response.task_id, jr.persistent_id
)
@@ -98,29 +98,18 @@
return reports_json
[email protected]('/reports/status/<report_id>')
-def report_status(report_id):
- db_session = db.get_session()
- db_report = db_session.query(PersistentReport).get(report_id)
- if db_report.status not in (celery.states.SUCCESS, celery.states.FAILURE):
- if db_report.result_key:
- # if we don't have the result key leave as is (PENDING)
- celery_task = Report.task.AsyncResult(db_report.result_key)
- db_report.status = celery_task.status
- db_session.add(db_report)
- db_session.commit()
- db_session.close()
- return json_response(status=db_report.status)
-
-
[email protected]('/reports/result/<report_id>.csv')
-def report_result_csv(report_id):
- response = ''
- db_session = db.get_session()
- db_report = db_session.query(PersistentReport).get(report_id)
- if not db_report:
- return json_error('no task exists with id: {0}'.format(report_id))
[email protected]('/reports/status/<task_id>')
+def report_status(task_id):
celery_task = Report.task.AsyncResult(db_report.result_key)
+ return json_response(status=celery_task.status)
+
+
[email protected]('/reports/result/<task_id>.csv')
+def report_result_csv(task_id):
+ celery_task = Report.task.AsyncResult(task_id)
+ if not celery_task:
+ return json_error('no task exists with id: {0}'.format(task_id))
+
if celery_task.ready():
task_result = celery_task.get()
@@ -139,47 +128,49 @@
task_rows.append(row)
writer.writeheader()
writer.writerows(task_rows)
- response = Response(csv_io.getvalue(), mimetype='text/csv')
+ return Response(csv_io.getvalue(), mimetype='text/csv')
else:
- response = json_response(status=celery_task.status)
+ return json_response(status=celery_task.status)
+
+
[email protected]('/reports/result/<task_id>.json')
+def report_result_json(task_id):
+ celery_task = Report.task.AsyncResult(task_id)
+ if not celery_task:
+ return json_error('no task exists with id: {0}'.format(task_id))
- db_session.close()
- return response
-
-
[email protected]('/reports/result/<report_id>.json')
-def report_result_json(report_id):
- response = ''
- db_session = db.get_session()
- db_report = db_session.query(PersistentReport).get(report_id)
- if not db_report:
- return json_error('no task exists with id: {0}'.format(report_id))
- celery_task = Report.task.AsyncResult(db_report.result_key)
if celery_task.ready():
task_result = celery_task.get()
- response = json_response(
+
+ # get the parameters from the database
+ db_session = db.get_session()
+ report = db_session.query(PersistentReport)\
+ .filter(PersistentReport.result_key == task_id)\
+ .one()
+ parameters = report.parameters
+ db_session.close()
+
+ return json_response(
result=task_result,
- parameters=json.loads(db_report.parameters),
+ parameters=json.loads(parameters),
)
else:
- response = json_response(status=celery_task.status)
-
- db_session.close()
- return response
+ return json_response(status=celery_task.status)
[email protected]('/reports/kill/<report_id>')
-def report_kill(report_id):
- db_session = db.get_session()
- db_report = db_session.query(PersistentReport).get(report_id)
- if not db_report:
- return json_error('no task exists with id: {0}'.format(report_id))
- celery_task = Report.task.AsyncResult(db_report.result_key)
- app.logger.debug('revoking task: %s', celery_task.id)
[email protected]('/reports/kill/<task_id>')
+def report_kill(task_id):
+ return 'not implemented'
+ #db_session = db.get_session()
+ #db_report = db_session.query(PersistentReport).get(task_id)
+ #if not db_report:
+ #return json_error('no task exists with id: {0}'.format(task_id))
+ #celery_task = Report.task.AsyncResult(db_report.result_key)
+ #app.logger.debug('revoking task: %s', celery_task.id)
#celery_task.revoke()
# TODO figure out how to terminate tasks. this throws an error
# which I believe is related to
https://github.com/celery/celery/issues/1153
# and which is fixed by a patch. however, I can't get things running
# with development version
#revoke(celery_task.id, terminate=True)
- return json_response(status=celery_task.status)
+ #return json_response(status=celery_task.status)
diff --git a/wikimetrics/static/css/site.css b/wikimetrics/static/css/site.css
index bb348a9..bd510b2 100644
--- a/wikimetrics/static/css/site.css
+++ b/wikimetrics/static/css/site.css
@@ -1,4 +1,5 @@
body { padding-top: 60px; padding-bottom: 60px; }
+table caption { padding: 16px; }
.navbar-fixed-top .nav { width: 80%; }
.navbar-fixed-top .nav li:last-child { color: #cacaca; float: right
!important; }
.navbar-fixed-top .nav li:last-child a { color: #0088cc; display:
inline-block; }
diff --git a/wikimetrics/templates/reports.html
b/wikimetrics/templates/reports.html
index c8993c4..c86adea 100644
--- a/wikimetrics/templates/reports.html
+++ b/wikimetrics/templates/reports.html
@@ -29,8 +29,8 @@
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
- <li><a target="_blank" data-bind="attr: {href:
'/reports/result/' + id + '.json'}">as JSON</a></li>
- <li><a target="_blank" data-bind="attr: {href:
'/reports/result/' + id + '.csv'}">as CSV</a></li>
+ <li><a target="_blank" data-bind="attr: {href:
'/reports/result/' + result_key + '.json'}">as JSON</a></li>
+ <li><a target="_blank" data-bind="attr: {href:
'/reports/result/' + result_key + '.csv'}">as CSV</a></li>
</ul>
</div>
</td>
--
To view, visit https://gerrit.wikimedia.org/r/75883
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I734cb70b5da83a2b68016623734e4486f1c79cee
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits