Skip to content

refactor(api): inject trigger subscription renewal scheduling - #45190

Open
hjlarry wants to merge 1 commit into
hjlarry/trigger-app-lifecyclefrom
hjlarry/trigger-renewal-scan
Open

hjlarry wants to merge 1 commit into
hjlarry/trigger-app-lifecyclefrom
hjlarry/trigger-renewal-scan

Conversation

@hjlarry

@hjlarry hjlarry commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of #39993. Stacked on #45188; merge that PR first.

Move the due-subscription scan and refresh-task lifecycle into an injected TriggerSubscriptionRefreshService. The repository returns detached candidates in bounded cursor-based batches and closes SQL sessions before Redis reservation or Celery publication. Cursor pagination avoids skipping later candidates when fast workers renew earlier rows during the scan.

Reserve each subscription with a UUID owner token and release reservations with compare-and-delete. New workers verify ownership before renewing. If publication fails, release failed and unsent reservations so the next scan can retry, while retaining reservations for tasks already published. Preserve the existing task names, queues, due thresholds and reservation TTL policy, and reuse the existing renewal service.

Keep task kwargs limited to tenant_id and subscription_id for rolling deployments. Carry the reservation token in Celery headers so older workers can still accept new messages; new bound tasks read the header and fall back to the legacy token "1" for older publishers. Older workers retain their existing cleanup behavior until they are replaced.

Cover due thresholds, cursor stability, session boundaries, publication failure cleanup and reservation ownership with SQL/Redis tests. The publisher test uses the real memory broker and a Celery consumer with the legacy two-argument signature; integration tests cover old and new messages reaching the new task and stale owners preserving replacement reservations.

Screenshots

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 verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@hjlarry
hjlarry added this pull request to stack #44506 October 31, 2026 03:59
@github-actions github-actions Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 76.91% 76.93% +0.02%
Strict coverage 76.59% 76.62% +0.02%
Typed symbols 66,243 66,331 +88
Untyped symbols 19,971 19,970 -1
Modules 3902 3906 +4

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.00000% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.12%. Comparing base (2cabe6c) to head (bf7fb91).

Files with missing lines Patch % Lines
...i/services/trigger/subscription_refresh_service.py 50.90% 26 Missing and 1 partial ⚠️
...pi/repositories/trigger/subscription_repository.py 68.96% 9 Missing ⚠️
api/tasks/trigger_subscription_refresh_tasks.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@                        Coverage Diff                        @@
##           hjlarry/trigger-app-lifecycle   #45190      +/-   ##
=================================================================
- Coverage                          88.12%   88.12%   -0.01%     
=================================================================
  Files                               5586     5587       +1     
  Lines                             334184   334262      +78     
  Branches                           66805    66811       +6     
=================================================================
+ Hits                              294491   294555      +64     
- Misses                             34474    34486      +12     
- Partials                            5219     5221       +2     
Flag Coverage Δ
api 87.64% <62.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant