Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Dec 5, 2025

Add ensure_workers() function to manage worker lifecycle

This PR introduces a new PostgreSQL function pgflow.ensure_workers() that manages the lifecycle of worker functions by:

  • Determining which worker functions need to be invoked based on their current state
  • Making HTTP requests to invoke those functions
  • Updating the last_invoked_at timestamp for invoked functions

The function implements different behavior based on environment:

  • In local mode: Always pings all enabled functions (for fast restart after code changes)
  • In production mode: Only pings functions that have no alive workers

Key features:

  • Respects debounce periods using the function's heartbeat_timeout_seconds setting
  • Uses Vault secrets for credentials in production with local fallbacks
  • Returns request IDs from pg_net for each HTTP request made
  • Comprehensive test suite covering all behavior scenarios

This function will be called by a cron job to ensure worker functions stay running, providing automatic recovery from worker failures.

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

⚠️ No Changeset found

Latest commit: c298fab

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

@nx-cloud
Copy link

nx-cloud bot commented Dec 5, 2025

View your CI Pipeline Execution ↗ for commit c298fab

Command Status Duration Result
nx run cli:e2e ✅ Succeeded 3s View ↗
nx run edge-worker:test:integration ✅ Succeeded 3m 42s View ↗
nx affected -t verify-exports --base=origin/mai... ✅ Succeeded 3s View ↗
nx affected -t build --configuration=production... ✅ Succeeded 31s View ↗
nx run edge-worker:e2e ✅ Succeeded 44s View ↗
nx affected -t lint typecheck test --parallel -... ✅ Succeeded 2m 14s View ↗
nx run client:e2e ✅ Succeeded 1m 9s View ↗
nx run core:pgtap ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-05 23:05:31 UTC

@jumski jumski force-pushed the 12-04-add_ensure_workers_sql_function_for_worker_invocation_orchestration branch from 7bc511b to c298fab Compare December 5, 2025 22:53
@jumski jumski force-pushed the 12-04-add_pg_net_pg_cron_and_supabase_vault_extensions_for_worker_management branch from eed5f12 to a529caf Compare December 5, 2025 22:53
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

🔍 Preview Deployment: Website

Deployment successful!

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

📝 Details:

  • Branch: 12-04-add_ensure_workers_sql_function_for_worker_invocation_orchestration
  • Commit: 7fc959563ef19f73a6b6c75bb4b5c80804b05ec7
  • View Logs

_Last updated: _

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