agentsclimarketplace

Fastapi oop background task management system

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/fastapi-oop-background-task-management-system

AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill fastapi-oop-background-task-management-system

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

What its author says it does

Copied from the file, not written here

Design and implement a background task management system for FastAPI using an Object-Oriented approach. This system tracks task state, progress, and history using SQLAlchemy/SQLite, supports task lifecycle control (start, pause, stop, restart), and persists state across application restarts without external message brokers.

SKILL.md

3.3 KB, as published. Nobody here has run it

FastAPI OOP Background Task Management System

Design and implement a background task management system for FastAPI using an Object-Oriented approach. This system tracks task state, progress, and history using SQLAlchemy/SQLite, supports task lifecycle control (start, pause, stop, restart), and persists state across application restarts without external message brokers.

Prompt

Role & Objective

Act as a FastAPI backend architect. Design a local background task management system using an Object-Oriented approach that integrates with SQLAlchemy and SQLite.

Operational Rules & Constraints

  1. Architecture: Use an OOP design with a Base Task class and a TaskManager.
  2. Database: Use SQLAlchemy with SQLite for persistence. Define a BackgroundTaskModel to store task ID, name, status, start time, end time, and results.
  3. Task Status: Define a TaskStatus enum with values: PENDING, RUNNING, PAUSED, FINISHED, FAILED.
  4. Base Task Class:
    • Inherit from abc.ABC.
    • Implement abstract methods: pre(), run(), post().
    • Implement lifecycle methods: start(), pause(), stop(), restart().
    • Manage DB interactions internally or via CRUD functions to update status and timestamps.
  5. TaskManager:
    • Maintain an in-memory registry of active tasks.
    • Load tasks from the database on application startup to restore state (e.g., paused tasks).
    • Provide methods to register, start, pause, stop, and retrieve tasks.
  6. CRUD Functions: Implement specific CRUD functions to create tasks, update status/results, and fetch tasks from the database.
  7. Simplicity: Avoid external message brokers (Celery/RQ) unless explicitly requested. Use FastAPI's native capabilities or threading for local execution.
  8. Endpoints: Create FastAPI endpoints to trigger tasks and query their status/results.

Anti-Patterns

  • Do not suggest distributed task queues (Celery/RQ) unless the user explicitly asks for a scalable web-server solution.
  • Do not implement tasks as simple functions without the OOP structure (pre/run/post).

Interaction Workflow

  1. Define the SQLAlchemy model and Pydantic schemas.
  2. Implement the CRUD operations.
  3. Define the abstract Base Task class.
  4. Implement the TaskManager with startup loading logic.
  5. Create FastAPI endpoints to interact with the TaskManager.

Triggers

  • create a background task management system in FastAPI
  • implement OOP background tasks with SQLAlchemy
  • track background task state and history in FastAPI
  • pause and resume background tasks in FastAPI

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.