51 lines
No EOL
1.3 KiB
Python
51 lines
No EOL
1.3 KiB
Python
"""
|
|
Task-related routes for the Podcastrr application.
|
|
"""
|
|
import logging
|
|
from flask import Blueprint, jsonify, request, current_app
|
|
from app.services.task_manager import task_manager
|
|
|
|
# Set up logging
|
|
logger = logging.getLogger(__name__)
|
|
|
|
tasks_bp = Blueprint('tasks', __name__)
|
|
|
|
@tasks_bp.route('/api/tasks', methods=['GET'])
|
|
def get_tasks():
|
|
"""
|
|
Get all tasks or filter by status.
|
|
"""
|
|
status = request.args.get('status')
|
|
tasks = task_manager.get_all_tasks()
|
|
|
|
if status:
|
|
tasks = [task for task in tasks if task.status.value == status]
|
|
|
|
return jsonify({
|
|
'tasks': [task.to_dict() for task in tasks]
|
|
})
|
|
|
|
@tasks_bp.route('/api/tasks/<task_id>', methods=['GET'])
|
|
def get_task(task_id):
|
|
"""
|
|
Get a specific task by ID.
|
|
"""
|
|
task = task_manager.get_task(task_id)
|
|
|
|
if not task:
|
|
return jsonify({'error': 'Task not found'}), 404
|
|
|
|
return jsonify(task.to_dict())
|
|
|
|
@tasks_bp.route('/api/tasks/clean', methods=['POST'])
|
|
def clean_tasks():
|
|
"""
|
|
Clean up old completed or failed tasks.
|
|
"""
|
|
max_age = request.json.get('max_age_seconds', 3600) if request.json else 3600
|
|
count = task_manager.clean_old_tasks(max_age)
|
|
|
|
return jsonify({
|
|
'message': f'Cleaned up {count} old tasks',
|
|
'count': count
|
|
}) |