def cancel(**kwargs):
    """Cancels work items based on their criteria.

    Args:
        **kwargs: Same parameters as the query() method.

    Returns:
        The number of tasks that were canceled.
    """
    task_list = _query(**kwargs)
    for task in task_list:
        task.status = WorkQueue.CANCELED
        task.finished = datetime.datetime.utcnow()
        db.session.add(task)
    return len(task_list)
Cancels work items based on their criteria.

    Args:
        **kwargs: Same parameters as the query() method.

    Returns:
        The number of tasks that were canceled.