Begin removing backoff_count from webhooks

What does this MR do and why?

This MR begins the process of removing backoff_count from the webhooks table.

backoff_count is always 3 less that recent_failures, because we only increment backoff_count after we reach 3 recent_failures, at the point where recent_failures is about to become 4.

This change begins the process of removing backoff_count, and instead we refer to recent_failures minus the disabling threshold failure count (TEMPORARILY_DISABLED_FAILURE_THRESHOLD) to let us derive the value of backoff_count rather than store it.

The existing logic has some subtle complexities about it, so being able to drop the use of one of the variables in the setting of auto-disabled webhooks will have a payoff in terms of simpler code.

How to set up and validate locally

On a rails console, the steps below should output the same result in master and on this branch:

Ensure you have at least on project hook on your instance.

webhook = ProjectHook.executable.take

webhook.recent_failures # => 0
webhook.disabled_until # => nil

webhook.backoff!
webhook.temporarily_disabled? # => false

webhook.backoff!
webhook.temporarily_disabled? # => false

webhook.backoff!
webhook.temporarily_disabled? # => false

webhook.backoff!
webhook.temporarily_disabled? # => true
webhook.recent_failures # => 4
webhook.disabled_until # => (1 minute from now)

If you need to reset the hook back to recent_failures = 0, disabled_until = nil, you can call #enable!:

webhook.enable!

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Luke Duncalfe

Merge request reports

Loading