zcash-grant-system/backend/grant/task/views.py

20 lines
641 B
Python
Raw Normal View History

2019-01-27 20:59:15 -08:00
from datetime import datetime
from flask import Blueprint, jsonify
from grant.task.jobs import JOBS
from grant.task.models import Task, tasks_schema
blueprint = Blueprint("task", __name__, url_prefix="/api/v1/task")
@blueprint.route("/", methods=["GET"])
def task():
2019-01-29 14:21:06 -08:00
tasks = Task.query.filter(Task.execute_after <= datetime.now()).filter_by(completed=False).all()
2019-01-27 20:59:15 -08:00
for each_task in tasks:
2019-01-28 19:00:55 -08:00
try:
JOBS[each_task.job_type](each_task)
except Exception as e:
# replace with Sentry logging
print("Oops, something went wrong: {}".format(e))
2019-01-27 20:59:15 -08:00
return jsonify(tasks_schema.dump(tasks))