Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Dec 5, 2025

Implement Worker Tracking for Improved Reliability

This PR adds functionality to track edge function workers more effectively, improving the reliability of worker management:

  1. Added two new methods to the Queries class:

    • trackWorkerFunction() - Registers an edge function for monitoring by the ensure_workers() cron job
    • markWorkerStopped() - Marks a worker as stopped during graceful shutdown
  2. Updated worker lifecycle implementations to call trackWorkerFunction() early in the startup process, which:

    • Sets last_invoked_at to prevent cron from pinging during startup (debounce)
    • Ensures proper monitoring of the worker by the cron job
  3. Enhanced the shutdown process in SupabasePlatformAdapter:

    • Replaced the previous approach of spawning a new edge function
    • Now signals worker death to the cron job by setting stopped_at
    • Allows immediate detection of worker termination
  4. Added comprehensive unit tests for the new functionality

These changes improve worker reliability by providing better signaling between workers and the monitoring system, ensuring faster recovery from failures and more efficient worker management.

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

⚠️ No Changeset found

Latest commit: b99dc84

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor Author

jumski commented Dec 5, 2025

@nx-cloud
Copy link

nx-cloud bot commented Dec 5, 2025

View your CI Pipeline Execution ↗ for commit b99dc84

Command Status Duration Result
nx run edge-worker:test:integration ✅ Succeeded 3m 54s View ↗
nx run cli:e2e ✅ Succeeded 4s View ↗
nx run edge-worker:e2e ✅ Succeeded 48s View ↗
nx affected -t verify-exports --base=origin/mai... ✅ Succeeded <1s View ↗
nx affected -t build --configuration=production... ✅ Succeeded 24s View ↗
nx affected -t lint typecheck test --parallel -... ✅ Succeeded 22s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-08 09:32:25 UTC

@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from b0988ce to 4106bd7 Compare December 5, 2025 22:53
@jumski jumski force-pushed the 12-05-add_setup_ensure_workers_cron_sql_function_for_cron_job_scheduling branch from 1f0dbdd to 133efc3 Compare December 5, 2025 22:53
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch 2 times, most recently from 49402ce to 8528e37 Compare December 6, 2025 09:46
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from 8528e37 to 4708057 Compare December 7, 2025 00:17
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from 4708057 to 2bfd197 Compare December 7, 2025 00:32
@jumski jumski force-pushed the 12-05-add_setup_ensure_workers_cron_sql_function_for_cron_job_scheduling branch from 133efc3 to 31944b5 Compare December 7, 2025 00:32
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from 2bfd197 to fea048b Compare December 7, 2025 11:08
@jumski jumski force-pushed the 12-05-add_setup_ensure_workers_cron_sql_function_for_cron_job_scheduling branch from 31944b5 to d43f53b Compare December 7, 2025 16:45
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from fea048b to 36c9a31 Compare December 7, 2025 16:45
@jumski jumski force-pushed the 12-05-add_setup_ensure_workers_cron_sql_function_for_cron_job_scheduling branch from d43f53b to aca53bc Compare December 8, 2025 05:23
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from 36c9a31 to 1d9cf44 Compare December 8, 2025 05:23
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

🔍 Preview Deployment: Website

Deployment successful!

🔗 Preview URL: https://pr-513.pgflow.pages.dev

📝 Details:

  • Branch: 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle
  • Commit: 34a8b8ea1394a3d2a5c72b0d7ca055e03e8ff1df
  • View Logs

_Last updated: _

Copy link
Contributor Author

jumski commented Dec 8, 2025

Merge activity

  • Dec 8, 8:07 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Dec 8, 9:26 AM UTC: Graphite rebased this pull request as part of a merge.
  • Dec 8, 9:33 AM UTC: @jumski merged this pull request with Graphite.

@jumski jumski changed the base branch from 12-05-add_setup_ensure_workers_cron_sql_function_for_cron_job_scheduling to graphite-base/513 December 8, 2025 09:17
@jumski jumski changed the base branch from graphite-base/513 to main December 8, 2025 09:24
@jumski jumski force-pushed the 12-05-integrate_trackworkerfunction_and_markworkerstopped_into_edge_worker_lifecycle branch from 1d9cf44 to b99dc84 Compare December 8, 2025 09:25
@jumski jumski merged commit 88f3a5b into main Dec 8, 2025
10 of 12 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

🚀 Production Deployment: Website

Successfully deployed to production!

🔗 Production URL: https://pgflow.dev

📝 Details:

  • Commit: 88f3a5b9f4bff07d02f452c22289e7ddc409f7a2
  • View Logs

Deployed at: 2025-12-08T10:33:24+01:00

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants