2 lines
3.5 KiB
JSON
2 lines
3.5 KiB
JSON
{"id":"chatcmpl-888d157ca5fdb58f","object":"chat.completion","created":1774197462,"model":"NousResearch\/Hermes-3-Llama-3.2-3B","choices":[{"index":0,"message":{"role":"assistant","content":"First, install Celery and Redis:\n\n```\npip install celery\npip install redis\n```\n\nHere is the complete Celery setup and tasks:\n\n```python\nfrom celery import Celery\nfrom flask import Flask\nfrom task_manager import TaskManager\n\napp = Flask(__name__)\napp.config['CELERY_BROKER_URL'] = 'redis:\/\/localhost:6379'\napp.config['CELERY_RESULT_BACKEND'] = 'redis:\/\/localhost:6379'\n\ncelery = Celery(app.name, broker=app.config['CELERY_BROKER_URL])\n\n@celery.task\ndef send_overdue_reminders():\n overdue_tasks = Task.query.filter(Task.completed == False, Task.due_date < datetime.now().date()).all()\n for task in overdue_tasks:\n send_email_reminder(task)\n\n@celery.task\ndef archive_completed_tasks():\n completed_tasks = Task.query.filter(Task.completed == True).filter(Task.created_at < datetime.now() - timedelta(days=30)).all()\n for task in completed_tasks:\n task_manager.delete_task(task.id)\n\n@celery.task\ndef create_new_recurring_tasks():\n recurring_tasks = Task.query.filter(Task.recurrence != None).all()\n for task in recurring_tasks:\n next_occurrence = task.next_occurrence\n while next_occurrence < datetime.now():\n next_occurrence += timedelta(days=1)\n task_manager.add_task(task.title, task.description, task.due_date, task.tags, task.depends_on, task.recurrence, next_occurrence, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, task.assigned_to)\n\n@app.route('\/email-reminders')\ndef email_reminders():\n send_overdue_reminders.delay()\n return \"Email reminders scheduled\"\n\n@app.route('\/archive-completed-tasks')\ndef archive_completed_tasks():\n archive_completed_tasks.delay()\n return \"Completed tasks archived\"\n\n@app.route('\/create-new-recurring-tasks')\ndef create_new_recurring_tasks():\n create_new_recurring_tasks.delay()\n return \"New recurring tasks created\"\n\nif __name__ == '__main__':\n app.run(debug=True)\n```\n\nIn this setup:\n\n- We create a Celery instance and configure it to use Redis as the broker and Redis as the result backend.\n- We define three Celery tasks:\n - send_overdue_reminders: Sends email reminders for overdue tasks.\n - archive_completed_tasks: Archives completed tasks older than 30 days.\n - create_new_recurring_tasks: Creates new instances of recurring tasks.\n- We define three API endpoints to trigger the Celery tasks:\n - \/email-reminders: Schedules an email reminder task for overdue tasks.\n - \/archive-completed-tasks: Schedules a task to archive completed tasks older than 30 days.\n - \/create-new-recurring-tasks: Schedules a task to create new instances of recurring tasks.\n\nTo use these Celery tasks, you can send HTTP requests to the corresponding API endpoints. The Celery tasks will be scheduled and executed in the background.\n\nNote: Make sure you have Redis running on your local machine and accessible by your Celery instance.","refusal":null,"annotations":null,"audio":null,"function_call":null,"tool_calls":[],"reasoning":null},"logprobs":null,"finish_reason":"stop","token_ids":null}],"service_tier":null,"system_fingerprint":null,"usage":{"prompt_tokens":25430,"total_tokens":26094,"completion_tokens":664,"prompt_tokens_details":null},"prompt_token_ids":null,"kv_transfer_params":null}
|