Asynchronous Tasks

Celery tasks for prompt app.

These tasks are i/o intensive operations for creating prompt and plugin history records with Celery workers in order to avoid blocking the main app thread. This is advance work to lay groundwork for future high-traffic scenarios.

  • purge_prompt_history() deletes the prompt history (PromptHistory, PromptToolCall, PromptPluginUsage, and idle Prompts) older than smarter_settings.prompt_history_max_age days. Celery Beat runs it daily.

smarter.apps.prompt.tasks.PROMPT_HISTORY_PURGE_BATCH_SIZE = 1000

The most rows that purge_prompt_history() deletes from a table in one statement.

smarter.apps.prompt.tasks.delete_in_batches(queryset)[source]

Delete the rows of queryset in batches of PROMPT_HISTORY_PURGE_BATCH_SIZE.

A large table isn’t locked in one long delete, e.g. on the first purge of a platform that has kept its prompt history for years.

Parameters:

queryset (QuerySet) – The rows to delete.

Returns:

The number of rows deleted, including those deleted by a cascade.

Return type:

int

smarter.apps.prompt.tasks.should_log(level)[source]

Check if logging should be done based on the waffle switch.