Skip to content

feat: clear free plan workflow run logs#29494

Merged
hjlarry merged 57 commits intolanggenius:mainfrom
hjlarry:p332
Jan 12, 2026
Merged

feat: clear free plan workflow run logs#29494
hjlarry merged 57 commits intolanggenius:mainfrom
hjlarry:p332

Conversation

@hjlarry
Copy link
Contributor

@hjlarry hjlarry commented Dec 11, 2025

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fix #29776

related PR:
#29842
#29829
#29638

Todo:
rm api/services/clear_free_plan_tenant_expired_logs.py in the future.

Usage

1. update db

to use the created_at index of workflow_runs table

flask db upgrade 

2. dry run

flask clean-workflow-runs --start-from="2024-01-01" --end-before="2024-01-31" --dry-run 

then you can get some logs like:

... Dry run complete. Would delete 2024 workflow runs between 2014-01-01T00:00:00 and 2024-01-02T00:00:00; related records: node_executions 2022, offloads 6066, app_logs 2024, trigger_logs 2022, pauses 2022, pause_reasons 2022 

you can compare with the sql result (maybe slow):

WITH params AS ( SELECT TIMESTAMP '2024-01-01 00:00:00' AS start_after, TIMESTAMP '2024-01-31 00:00:00' AS end_before ) SELECT 'workflow_runs' AS table_name, COUNT(*) AS record_count FROM workflow_runs, params WHERE created_at >= start_after AND created_at < end_before UNION ALL SELECT 'workflow_node_executions', COUNT(*) FROM workflow_node_executions, params WHERE created_at >= start_after AND created_at < end_before UNION ALL SELECT 'workflow_node_execution_offload', COUNT(*) FROM workflow_node_execution_offload, params WHERE created_at >= start_after AND created_at < end_before UNION ALL SELECT 'workflow_app_logs', COUNT(*) FROM workflow_app_logs, params WHERE created_at >= start_after AND created_at < end_before UNION ALL SELECT 'workflow_trigger_logs', COUNT(*) FROM workflow_trigger_logs, params WHERE created_at >= start_after AND created_at < end_before UNION ALL SELECT 'workflow_pauses', COUNT(*) FROM workflow_pauses, params WHERE created_at >= start_after AND created_at < end_before UNION ALL SELECT 'workflow_pause_reasons', COUNT(*) FROM workflow_pause_reasons, params WHERE created_at >= start_after AND created_at < end_before ORDER BY table_name; 

4. run

To clear run logs within a specified time range.

flask clean-workflow-runs --start-from="2024-01-01" --end-before="2024-01-31" 

To clear the run logs before 90 days:

flask clean-workflow-runs --days=90 

To schedule run the clear task:

ENABLE_WORKFLOW_RUN_CLEANUP_TASK=true 

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
@hjlarry hjlarry changed the title WIP: clear free plan workflow run logs feat: WIP: clear free plan workflow run logs Dec 11, 2025
@hjlarry

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@hjlarry

This comment was marked as outdated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new feature to clean up expired workflow run logs for free-tier tenants. It includes a new CLI command, a scheduled Celery task, a database migration to add a necessary index, and the core service logic for performing the cleanup in batches. The implementation is robust, with good test coverage for the new components. My review includes a suggestion to optimize the database deletion logic for better performance and memory efficiency.

@hjlarry hjlarry requested a review from hj24 December 12, 2025 01:51
@hjlarry hjlarry requested a review from MRZHUH as a code owner December 18, 2025 08:51
MRZHUH
MRZHUH previously approved these changes Dec 18, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 18, 2025
@hjlarry hjlarry removed the lgtm This PR has been approved by a maintainer label Dec 18, 2025
@hjlarry hjlarry requested a review from hj24 December 19, 2025 00:45
crazywoola
crazywoola previously approved these changes Dec 24, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 24, 2025
@hjlarry hjlarry marked this pull request as draft December 25, 2025 03:01
@hjlarry hjlarry self-assigned this Dec 25, 2025
@hjlarry hjlarry mentioned this pull request Dec 29, 2025
5 tasks
Copy link
Contributor

@hj24 hj24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except the migration version, others LGTM

@hjlarry hjlarry marked this pull request as ready for review January 12, 2026 07:55
Copy link
Contributor

@hj24 hj24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hjlarry hjlarry merged commit 51ea87a into langgenius:main Jan 12, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request 🌊 feat:workflow Workflow related stuff. lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

6 participants