Skip to content

Split webhook logic from MergeRequests::RefreshService

What does this MR do and why?

Extract web hooks execution from MergeRequests::RefreshService into separate service and worker

This MR continues the refactoring of MergeRequests::RefreshService by extracting web hooks execution into dedicated components to improve performance and separation of concerns.

Key changes:

New Components:

  • MergeRequests::Refresh::WebHooksService - Handles merge request webhook execution for branch updates
  • MergeRequests::Refresh::WebHooksWorker - Processes webhook execution asynchronously in the background

Feature Flag Integration:

  • Introduces split_refresh_worker_web_hooks feature flag for gradual rollout
  • When enabled: webhook execution moves to background worker
  • When disabled: maintains current synchronous behavior for backward compatibility

Performance Benefits:

  • Reduces blocking time in the main refresh flow by moving webhook execution to background processing
  • Improves scalability of merge request operations
  • Maintains idempotency and proper error handling

Implementation Details:

The new WebHooksService inherits from BaseService and:

  • Creates a Gitlab::Git::Push object with the provided revision information
  • Iterates through merge requests for the source branch
  • Executes webhook calls with 'update' action and old revision context

The WebHooksWorker is configured with:

  • Low urgency and CPU resource boundary (weight: 2)
  • Idempotent execution with deduplication until executed
  • Database health signal deferral for improved reliability
  • Proper error handling for missing projects/users

This refactoring is part of the broader effort to split MergeRequests::RefreshService into focused, maintainable components.

Part of: #554081 (closed)

How to set up and validate locally

  1. Create a test project with webhooks:

    • Go to your GitLab instance (usually http://localhost:3000)
    • Create a new project or use an existing one
    • Go to Settings > Webhooks
    • Add a webhook URL (you can use a service like https://webhook.site for testing)
    • Select "Merge request events" trigger
    • Save the webhook
  2. Enable the feature flag:

    # In Rails console (gdk rails console) Feature.enable(:split_refresh_worker_web_hooks)

  3. Create a merge request:

    • Create a new branch in your test project
    • Make some commits
    • Create a merge request from this branch to main/master
  4. Check in the web hook site that the hooks pushed

  5. **Check in the sidekiq.log that the new webhook worker is executed

Edited by Marc Shaw

Merge request reports

Loading