Exemplo n.º 1
0
def fetch_lock(task_id):
    """Fetch the time (in seconds) until the current user's
    lock on a task expires.
    """
    if not current_user.is_authenticated:
        return abort(401)

    task = task_repo.get_task(task_id)

    if not task:
        return abort(400)

    scheduler, timeout = get_project_scheduler_and_timeout(task.project_id)

    ttl = None
    if scheduler in (Schedulers.locked, Schedulers.user_pref):
        task_locked_by_user = has_lock(task.id, current_user.id, timeout)
        if task_locked_by_user:
            locks = get_locks(task.id, timeout)
            ttl = locks.get(str(current_user.id))

    if not ttl:
        return abort(404)

    seconds_to_expire = float(ttl) - time()
    res = json.dumps({'success': True, 'expires': seconds_to_expire})

    return Response(res, 200, mimetype='application/json')
Exemplo n.º 2
0
def cancel_task(taskId=None):
    """Unlock task upon cancel so that same task can be presented again."""
    if not current_user.is_authenticated():
        return abort(401)

    data = request.json
    projectname = data.get('projectname', None)
    project = project_repo.get_by_shortname(projectname)
    if not project:
        return abort(400)

    projectId = project.id
    userId = current_user.id
    scheduler, timeout = get_project_scheduler_and_timeout(projectId)
    if scheduler in (Schedulers.locked, Schedulers.user_pref):
        task_locked_by_user = has_lock(projectId, taskId, userId, timeout)
        if task_locked_by_user:
            release_lock(projectId, taskId, userId, timeout)
            current_app.logger.info(
                'Project {} - user {} cancelled task {}'.format(
                    project.id, current_user.id, taskId))

    return Response(json.dumps({'success': True}),
                    200,
                    mimetype="application/json")